manage_relationship to create another resource `belongs_to` relation
Hi, I noticed I have a pretty common thing to define an action on a resource, which will automatically created related resources that is in the scope of the action. I wanted to know how to do that declaratively
Example.
I want to define a :create on Organization, that will create a member with actor
Currently I am doing it in a custom function that calls
But I don't like this way, as there is a manage_relationship Resource action, but I don't want anything passed as arguments
Solution:Jump to solution
manage_relationship
will eventually call a create/update action etc., and you are providing inputs for it here6 Replies
That's the only way currently.
do you plan on having something like
set_attribute
, like set_relation
?
or make a duplicate of manage_relationship, which does not expect an argument, but a value?No current plans, since often when you do this it's computed state for the relationship in some way
There isn't anything wrong with having custom changes like that
You can clean it up by putting it into a module and making it generic if you like
i.e
If you want it to visually look the same, you can do this
and then in your resource
Can I pass a Changeset to manage_relationship?
something like
so I can define the default role for :create to be "owner"
No, you can only pass action inputs to the underlying action
Solution
manage_relationship
will eventually call a create/update action etc., and you are providing inputs for it here