Ash FrameworkAF
Ash Framework3y ago
25 replies
Arjun Bajaj

How do you set an attribute to the join resource when creating?

For example, I have a
User
and an
Org
, joined by a
many_to_many
through a Join Resource
UserOrg
.

UserOrg
has an attribute
:role
. How do I set the
role
on the
UserOrg
when creating an
Org
?

create :create do
  accept [:name]
  argument :user_id, :binary

  change fn changeset, %{actor: actor} = _context ->
    changeset |> Ash.Changeset.set_argument(:user_id, actor.id)
  end

  change manage_relationship(:user_id, :users, type: :append_and_remove)
  # ^^^ somehow set :role to :owner in this relationship
end
Was this page helpful?