Example of :create action with simultaneous assignment of relationship
Perhaps I'm too influenced by Django, but I've been trying to :create a new instance of a resource that
belongs_to
two other resource types by passing the other resources' .id
values as parameters in the map, to no avail.
Following the Getting Started guide, I understand how I first create the Ticket resource instance and a Representative resource instance and then use the :assign
update action to assign the ticket to the representative.
However, how would I go about creating a ticket with the representative already being assigned during the :create
action?
If this is possible, what would it look like if I were to create a ticket with more than one related resources at once?
Or do I first need to create, then update/assign?5 Replies
In other words, is there a way to manage_relationship during :create?
Definitely should not need to implement a follow-up update
I think in your case you might just want
attribute_writable? true
on the belongs_to
relationships
and then the generated foo_id
attribute will be writableThank you @Zach Daniel, now it works. I think it would be a good addition to the documentation, could I submit a PR on github?
Yes please ๐
๐
https://github.com/ash-project/ash/pull/509 here you go!
GitHub
Update "Get Started" guide with an example by waseigo ยท Pull Reques...
Added example of how to write the Representative ID directly into the Ticket during Ticket creation. Based on https://discord.com/channels/711271361523351632/1073248091324551228/1073249825363075102...