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 ```elixir defmodule Post do ...
Jump to solution
2 Replies
mml
mmlOP4mo ago
(for instance, i want post.handle to be "synthesized" (joined) from the post.created_by.handle) i tried
Post.read("id", load: [created_by: [:handle]])
Post.read("id", load: [created_by: [:handle]])
to no avail, but i think that's the gist of it
Solution
barnabasj
barnabasj4mo ago
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]
defmodule Post do

....

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

Post.read("id", load: [:handle]

Did you find this page helpful?