AE
Ash Elixirโ€ข3y ago
waseigo

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
waseigo
waseigoOPโ€ข3y ago
In other words, is there a way to manage_relationship during :create?
ZachDaniel
ZachDanielโ€ข3y ago
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 writable
waseigo
waseigoOPโ€ข3y ago
Thank you @Zach Daniel, now it works. I think it would be a good addition to the documentation, could I submit a PR on github?
ZachDaniel
ZachDanielโ€ข3y ago
Yes please ๐Ÿ™‚ ๐Ÿ™‡
waseigo
waseigoOPโ€ข3y ago

Did you find this page helpful?