AE
Ash Elixir•2y ago
Blibs

use embedded fields inside expr

I have a resource that contains as one of its attributes another resource that is an embedded one.
defmodule Pacman.Markets.Property.Contact do
@moduledoc false

use Ash.Resource,
data_layer: :embedded

attributes do
attribute :full_address, :string do
constraints max_length: 255
end
end
end

defmodule Pacman.Markets.Property do
@moduledoc false

use Ash.Resource,
data_layer: AshPostgres.DataLayer

attributes do
alias Pacman.Markets.Property.Contact

attribute :contact, Contact

...
end
end
defmodule Pacman.Markets.Property.Contact do
@moduledoc false

use Ash.Resource,
data_layer: :embedded

attributes do
attribute :full_address, :string do
constraints max_length: 255
end
end
end

defmodule Pacman.Markets.Property do
@moduledoc false

use Ash.Resource,
data_layer: AshPostgres.DataLayer

attributes do
alias Pacman.Markets.Property.Contact

attribute :contact, Contact

...
end
end
When I try to access one of the embedded resource fields, ash will fail when I run the read action:
read :my_action do
filter expr(full_address == contact.full_address)
end
read :my_action do
filter expr(full_address == contact.full_address)
end
The error message will be "filter: Invalid reference contact.full_address at relationship_path [:contact]"
2 Replies
ZachDaniel
ZachDaniel•2y ago
contact[:full_address] 😄
Blibs
BlibsOP•2y ago
Makes sense haha, thanks!

Did you find this page helpful?