If both sides of a unidirectional ToMany (e.g. OneToMany or ManyToMany) self
relationship are removed, the instances are removed from the database in random
order. This might lead to a foreign key violation, if the non-owning side is
removed first. This is b/c the join table entries are only removed when the
owning side is removed. The non-owning side in a unidirectional relationship
doesn't know about the relationship at all. Note, that it very much depends on
the order of removals, if a foreign key violation occurs. The order can not be
An example for a unidirectional self relationship might be if an Employee, who
is also a manager has a collection of managed Employees, but the Employees don't
have a relationship field.
To solve this problem, the way removals from join tables are done in TLE must be
changed. Currently, join table entries are removed when the owning side is
removed. A possible fix would introduce a phase removing join table entries
before the associated instances are removed.
This issue is filed as a follow-up for issue 2991.