Add order to many_to_many table

Hi all, I have a Human and Gift resources. Then I also have a HumanGifts many_to_many table to join the two resources. This table contains a human_id, a gift_id and an order of type integer. What I am trying to do is make it so that when a Human creates and sorts their gifts in the UI, the gifts are saved in the Gifts table but their order is persisted in the HumanGifts table. I have tried different things all day but have not been able to get this working via manage_relationships which I have experience with but only with has_many. What would be the correct way to achieve what I want? Thank you!
Solution:
and maybe order_is_key ```elixir update :manage_gifts do argument :gifts, {:array, :map}...
Jump to solution
2 Replies
barnabasj
barnabasj2mo ago
the join_keys option should give you what you want.
Solution
barnabasj
barnabasj2mo ago
and maybe order_is_key
update :manage_gifts do
argument :gifts, {:array, :map}

change manage_relationships(:gifts, order_is_key: :order, join_keys: :order, type: :direct_control)
end
update :manage_gifts do
argument :gifts, {:array, :map}

change manage_relationships(:gifts, order_is_key: :order, join_keys: :order, type: :direct_control)
end
you might need to play around with the type / on_* options to get the exact behaviour you want

Did you find this page helpful?