[odb-users] Bidirectional Relationship Primary Key
boris at codesynthesis.com
Fri Feb 13 05:26:27 EST 2015
Chen Weiguang <CWeiguan at dso.org.sg> writes:
> Currently I am able to generate the schema for X_Y relationship table
> (X_id, Y_id), but with no primary key when compiling with ODB compiler.
> I would like the schema to have either a composite primary key, or
> unique index across the two fields when compiling with ODB compiler,
> so as to prevent multiple addition of same relationship. Is there a
> way to do this?
The only way to do this currently is by executing a piece of SQL that
adds the index (or the primary key) manually, after the schema creation.
I.e., ALTER TABLE ADD CONSTRAINT...
I've also added a TODO item to support this better. I think the clean
way would be the 'unique' pragma that tells ODB there are no duplicate
#pragma db unique // No multiple pointers to the same object.
Then ODB can generate the primary key, which I believe is the idiomatic
More information about the odb-users