Additional attributes in many-to-many relations
Hi there,
I'm using a many-to-many relation between two resources. The resources
Ingredient
and Store
are related through the resource Price
(an ingredient is available at a store for a certain price).
The Price
resource has the additional attributes :amount
and :price
.
Ideally, I'd like to have an action on the Ingredient resource to add a store. Somewhat like this:
This action should create a new price with the given attributes, but I'm struggling to implement the action. On other many-to-many relations, I've used change manage_relationship(:stores, type: :append)
but I can't figure out how to add the additional arguments.1 Reply
Hey there! Been a bit busy today, but what you’re looking for is the more specific instructions that you can use for manage_relationship
For example:
on_no_match: {:update, :update, :update, [:join, :fields]}
Check out the docs for Ash.Changeset.manage_relationship
Additionally, you can manage the join relationship instead of the many to many relationship.