Ash FrameworkAF
Ash Framework3y ago
2 replies
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


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


The error message will be "filter: Invalid reference contact.full_address at relationship_path [:contact]"
Was this page helpful?