Following my last question ([Solved] Nilify many-to-many relationships on update) about :on_replace behaviors, my application is nearing completion. Thanks again to those who helped.
I’ve been suprised by a behavior desired by users that I did not anticipate : It seems that when a model has a one-to-many or many-to-many relationship to another, ecto is really clever in calculating the changes.
If model A has a relation to the models Bs with ids [1,2,3,4,7] and that I pass in put_assoc the models Bs [1,7,2,3,4] (same models, different order), the join table isn’t flushed then re-inserted.
In other words, I relied on insertion order in join tables without thinking about it.
Is there a solution to force this delete/insert cycle of those entries without resorting to join schemas and an order column / manually deleting the entries when there’s a non-empty list as input of those relationships ?