[odb-users] Best Practice deleting persistent objects

Steven Côté steven.cote at gmail.com
Fri Apr 4 08:06:21 EDT 2014


>
> > Then I create a user and add it to a group. I then subsequently call
> > erase() on that user. Now, I'm still getting the "FOREIGN KEY constraint
> > failed" exception that I was getting before. I had thought that by adding
> > the relationship to group from the user class, it would have
> auto-magically
> > removed the corresponding entry from the group_Members table when
> erasing a
> > user.
>
> If you want to be able to erase user without having to clean any
> references, then you need to put the non-inverse side of the
> relationship in the user class.
>
> Think about it this way: the non-inverse side is the only relationship
> that actually exists in the database. So if erasing an object must also
> take down the relationship, then the non-inverse side should be part of
> that object.
>

Ah ok, that makes sense. And sure enough, switching which class had the
inverse statement makes all my unit tests pass. Thanks for the help guys!


More information about the odb-users mailing list