Ash FrameworkAF
Ash Framework7mo ago
5 replies
mml

Single attribute join via belongs_to

What is the correct way to join a subset of attributes to a resource through a belongs_to relation?

For instance, with post has many users and post belongs_to user, i want only the public?(true) fields joined onto the post struct

does this belong in a prepare() maybe? or is it a calculation?
Solution
you can do that with a calculation

defmodule Post do

....

  calculations do
    calculate :handle, :string, expr(created_by.handle)
  end
end

Post.read("id", load: [:handle]
Was this page helpful?