[odb-users] Many to many relationships - Insertion and deletion
Nicolas ALBEZA
n.albeza at gmail.com
Fri Aug 19 12:52:40 EDT 2011
Hello odb-users,
I'm currently using ODB's many-to-many relationships in my projects, and i
was wondering how to insert and delete entires efficiently.
My classes look like (most of it omitted for clarity):
class Project
{
#pragma db value_not_null unordered
list<lazy_shared_ptr<Account> > members;
}
class Account
{
#pragma db value_not_null inverse(members)
list<lazy_weak_ptr<Project> > projects;
}
Currently, to add an Account to a Project, i'm doing something along the
lines of :
shared_ptr<Account> account = db->find(...);
shared_ptr<Project> project = db->find(...);
project->members.push_back(account);
db->update(project);
Unfortunately, when looking at MySQL's query log, i can see the following
queries being executed :
- A full update of the project entry
- Deletion of entries in the junction table
- And finally, insertion of an entry in the junction table
The two first steps seem unnecessary, so i was wondering if there was a
better approach to do this.
Thanks !
Regards,
--
ALBEZA "Pause" Nicolas
More information about the odb-users
mailing list