diff --git a/test/embeddable_resource_test.exs b/test/embeddable_resource_test.exs index b987f90d..ead20aa8 100644 --- a/test/embeddable_resource_test.exs +++ b/test/embeddable_resource_test.exs @@ -23,6 +23,28 @@ defmodule AshPostgres.EmbeddableResourceTest do Ash.load!(post, :calc_returning_json) end + test "can filter on a doubly-nested embedded resource field" do + Author + |> Ash.Changeset.for_create(:create, %{ + bio: %{address: %{city: "Sydney", country: "AU"}} + }) + |> Ash.create!() + + Author + |> Ash.Changeset.for_create(:create, %{ + bio: %{address: %{city: "Melbourne", country: "AU"}} + }) + |> Ash.create!() + + results = + Author + |> Ash.Query.filter(bio[:address][:city] == "Sydney") + |> Ash.read!() + + assert length(results) == 1 + assert hd(results).bio.address.city == "Sydney" + end + test "embeds with list attributes set to nil are loaded as nil" do author = Author diff --git a/test/support/resources/bio.ex b/test/support/resources/bio.ex index 0dce7e04..8d03b31e 100644 --- a/test/support/resources/bio.ex +++ b/test/support/resources/bio.ex @@ -22,5 +22,7 @@ defmodule AshPostgres.Test.Bio do allow_nil?(true) default(nil) end + + attribute(:address, AshPostgres.Test.BioAddress, public?: true) end end diff --git a/test/support/resources/bio_address.ex b/test/support/resources/bio_address.ex new file mode 100644 index 00000000..30ce5425 --- /dev/null +++ b/test/support/resources/bio_address.ex @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2019 ash_postgres contributors +# +# SPDX-License-Identifier: MIT + +defmodule AshPostgres.Test.BioAddress do + @moduledoc false + use Ash.Resource, data_layer: :embedded + + actions do + default_accept(:*) + defaults([:create, :read, :update, :destroy]) + end + + attributes do + attribute(:city, :string, public?: true) + attribute(:country, :string, public?: true) + end +end