Add value to manage_relationship input from current resource
I have this resource
I am creating the
:accept
for invitation, which should create a Member where the role will be the same as the Invitation's role, something like arg
or actor
but an attr
(it does not exist, I just invented it to show what I am looking for
(PS. relation function is just making a manage_relationship with passed arguments)9 Replies
you can use the lower level
Ash.Changeset.manage_relationship
in a custom change
which accepts whatever value you wantbut how do I get the role attribute from the original resource which is going to be updated
is it always in the changeset?
or do I have to load it somehow
You have a couple ways
its in
changeset.data
You can also do an after action hook where you get the resultwill it always be in changeset.data? Does it always load the resource?
I am just thinking of atomic updates,
Should I say somewhere that this change is not atomic?
it will happen automatically
if you add a change that can't be done atomically
it will yell at you to add
require_atomic? false
so manage_relationship can sometimes be atomic and sometimes not, right?
currently its never atomic
If you use an after action hook we allow it to be annotated as atomic for convenience
which is a slightly less strict version of atomicity but its important for practicality
understood, thanks a lot
but you still have to make a custom change and declare that your after action logic is safe in that way