Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/embeddable_resource_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@
Ash.load!(post, :calc_returning_json)
end

test "can filter on a doubly-nested embedded resource field" do

Check failure on line 26 in test/embeddable_resource_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test can filter on a doubly-nested embedded resource field (AshPostgres.EmbeddableResourceTest)

Check failure on line 26 in test/embeddable_resource_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test can filter on a doubly-nested embedded resource field (AshPostgres.EmbeddableResourceTest)

Check failure on line 26 in test/embeddable_resource_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test can filter on a doubly-nested embedded resource field (AshPostgres.EmbeddableResourceTest)
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
Expand Down
2 changes: 2 additions & 0 deletions test/support/resources/bio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ defmodule AshPostgres.Test.Bio do
allow_nil?(true)
default(nil)
end

attribute(:address, AshPostgres.Test.BioAddress, public?: true)
end
end
18 changes: 18 additions & 0 deletions test/support/resources/bio_address.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2019 ash_postgres contributors <https://github.com/ash-project/ash_postgres/graphs/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
Loading