[odb-users] Best Practice deleting persistent objects

Steven Côté steven.cote at gmail.com
Fri Apr 4 05:53:30 EDT 2014


>
> You just did. This is a many-to-many relationship with one side
> inverse. There is a section in manual on this kind of relationships.


Sounds good when I read it, but I just gave it a try and it's still not
working the way I would have expected.

So, currently the classes look like this:

class user;

 #pragma db object
class group
{
   ...
   #pragma db value_not_null unordered
   std::vector<lazy_shared_ptr<user> > Members_;
};

#pragma db object
class user
{
   ...
   #pragma db value_not_null inverse(Members_)
   std::vector<lazy_weak_ptr<group> > Groups_;
};

This creates the many-to-many relationship in the schema that I was
expecting, so that's all good.

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. Is that assumption wrong?


More information about the odb-users mailing list