[odb-users] Relational tables with an association table
Adam Walters
adamw at animetix.com
Thu Jul 18 15:34:59 EDT 2013
Hi Boris,
Thanks for the quick feedback. I will try using the bi-directional approach and see if I can avoid the extra table.
Cheers,
Adam
________________________________________
From: Boris Kolpackov <boris at codesynthesis.com>
Sent: Thursday, July 18, 2013 10:34 AM
To: Adam Walters
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Relational tables with an association table
Hi Adam,
Adam Walters <adamw at animetix.com> writes:
> What I am having a hard time understanding is why is this additional
> table required as it appears to be used to perform the join between
> the PC and the CT tables?
Because that's the relationship you specified. You basically have
a unidirectional to-many relationship (every PC object can point
to multiple CT objects).
You definitely need to read up on inverse relationships since I
believe that the solution to your problem. If you turn this into
a bidirectional relationship (at the tables level any relationship
is always bidirectional), then you can choose which side actually
results in a table/column. And in your case you can choose to make
the CT pointer the straight (non-inverse) side to avoid the extra
table. Try this and see what schema you get:
class PC
{
#pragma db inverse (_pc)
std::vector< std::unique_ptr<CT> > _ct;
};
class CT
{
std::unique_ptr<PC> _pc;
};
> In my case, I presume the id field would contain the id of a PC
> record and the value field would contain the same value,
No, the value will contain the id of the CT row.
> If I have to create a separate table for each 1-to-many relationship
> i define, does the ODB insert mechanism populate these for me
> automatically?
Yes, of course.
Boris
More information about the odb-users
mailing list