Ecto has_many :on_delete protect

As supplementary:

  • above code just do data consistency, it is not helpful for user experience —— You shouldn’t just popup a model, and tell users “database error occurs”.
  • try to use Ecto.Changeset.no_assoc_constraint before deleting any referenced rows, :on_delete is just the last line of defense for data consistency.