[odb-users] Create a foreign key constrain to a unique column of other table

Boris Kolpackov boris at codesynthesis.com
Wed Sep 13 13:32:56 EDT 2017

Vassilios Kountouriotis <b.kountouriotis at gmail.com> writes:
> I'm mapping my existing database schema to ODB. That's why I have these
> weird issues...
> Furthermore, if this helps a bit, I'm really not interested in
> maintaining the loading capability from Log to the Ticket. All I'm
> interested in is creating the constraint that LogTicketID *must* be a
> value from Ticket.TicketID.

Well, if you are using the existing database schema then you already
have the constraint (ODB doesn't do any extra checking in this context
relying on the database to enforce constraints). Since you are not
interested in loading the pointed-to object (which, BTW, you can still
do with an object loading view if you change your mind), simply make
the member a string and be done with it:

std::string LogTicketID;


More information about the odb-users mailing list