[odb-users] Many-to-many adding values to join table.
Rafael Pena
pena.rd at gmail.com
Sat Jul 9 15:16:34 EDT 2011
I am a bit confused about the many-to-many relationship. How do I add the
relationship when when both entities already exist?
These are my classes:
class PartData {
public:
PartData(const PartData& orig);
virtual ~PartData();
private:
PartData() {
}
friend class odb::access;
#pragma db id auto
//other fields go here
unsigned long partdataid;
#pragma db not_null inverse(parts)
std::vector<weak_ptr<TestData> > tests;
};
class TestData {
public:
TestData(long testnum);
TestData(const TestData& orig);
virtual ~TestData();
private:
TestData() {
}
friend class odb::access;
#pragma db id auto
unsigned long testdataid;
//other fields go here
#pragma db not_null unordered
std::vector<shared_ptr<PartData> > parts;
};
When both already exist and I add one (parts.push_back()) to the other. How
do I add to the join table? I tried update and persist but neither added the
value to the table. I am confused. Anybody have an example? I looked through
the docs but I can't find any details.
Right now I am just running an insert query:
db->execute("insert into TestData_parts values (" + testid+","+
partdataids.str() + ")");
Although it works, is there another way to do it?
David
More information about the odb-users
mailing list