How To Delete Many-To-Many Relation In Elixir Ecto — Tentamen Software Testing Blog
Based on this excellent blog post, Many to many relationships with Ecto by Nuno Marinho, we successfully implemented many-to-many relations in our application. However, we needed a feature that required removing (deleting) many-to-many relations without deleting entities involved in this relation.
Deleting Many-To-Many Relation in Elixir Ecto
In Nuno post, you can find four steps on how to do proper many-to-many relation between
Users using Elixir Ecto powers. However, one step is missing, how to remove the relation between
The Wrong Way
Our first implementation was to do:
but that also deleted a
Then we found this excellent advice on the Elixir forum:
Repo.delete/2 expects a changeset_or_struct as the first argument. It looks like you’re piping an #Ecto.Query ( ie.queryable) into it. I believe delete_all/2 66 is what you’re looking for.
without the query implementation.
The Query For Deleting Many-To-Many Relation In Elixir Ecto
Originally published at https://blog.tentamen.eu on September 14, 2020.