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

Boris Kolpackov boris at codesynthesis.com
Mon Sep 11 10:22:25 EDT 2017


Vassilios Kountouriotis <b.kountouriotis at gmail.com> writes:

> For example assume I have a table 'Ticket' with 'AI_PK' as the primary
> key (auto increment INT) and a 'TicketID' as a unique CHAR(36). Now,
> in my Log table, how can I create a foreign key column LogTicketID
> pointing to the Ticket.TicketID?

I don't think there is an automatic way to do this. The two possible
ways that I can see are:

1. Map TicketID to the object id and AI_PK to an ordinary data member
   (if at all). The only drawback of this approach is that you won't
   get the auto-assigned id back into the data member on persist.

2. Make LogTicketID non-pointer or custom/transient pointer and load
   it manually (e.g., with an object loading view). If it was eager
   (i.e., non-lazy), then the database operation callback would be
   a natural place to do this.

Boris



More information about the odb-users mailing list