Ash FrameworkAF
Ash Frameworkβ€’3y agoβ€’
37 replies
Myrmyr

Embed `has_one` relationship into resource

Let's say I have a resource A.
It has relationship:
  relationships do
    has_many :a_version, Ash.Api.AVersion do
      sort created_at: :desc
    end
  end

which holds some fields that should be versioned if any changes happen, it has at least one :a_version
Let's say the AVersion has the a :price attribute.

We can define the manual fake "has_one" relationship, by making a query that takes the latest version of AVersion.

Now, here's question. Is there any way to embed the fields from the latest AVersion from the fake "has_one" manual relationship into A so that they can be:
- Accessed at top-level like A.price
- Loaded automatically
as if they were attributes of the A itself?
Was this page helpful?