Hey all! I’m implementing something similar to the polymorphic todo list in Plataformatec’s What’s new in Ecto 2.1 (I’ll be using the todo list example in this post). It works fine, however getting deletion in a one-to-many relationship (since any TodoItem
will only be on one TodoList
or Project
) using a join table is a bit tricky. I’ve set the on_delete
option on the references in the todo_list_items
and the projects_items
tables to :delete_all
, which works fine for deleting the join table record when a TodoItem
, a TodoList
, or a Project
is deleted. As expected though, when a TodoList
or a Project
is deleted, the TodoItem
s associated with it aren’t deleted, which would be desirable in my domain since, using the todo list as an example, moving a TodoItem
to a different Project
or TodoList
wouldn’t make sense. I’ve found in the Ecto docs where this is how :delete_all
behaves (which makes sense for the majority of many_to_many uses), but I was wondering if there is a setting in Ecto that would delete the TodoItem
s when a Project
or TodoList
is deleted? Or will I have to do this myself either in an Ecto.Multi
or with a PostgreSQL trigger?