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

Vassilios Kountouriotis b.kountouriotis at gmail.com
Mon Sep 11 04:34:29 EDT 2017


Hello,

I'm trying to map my tables to odb and can't seem to find out how to
create a foreign key constraint towards a unique column (but not the
primary key) of another table.

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 understand that this is not the most efficient, but this is what
we've got currently)

I've set this relationship as:

#pragma db not_null
odb::lazy_shared_ptr<DB_Ticket> LogTicketID;

By default, ODB maps LogTicketID to AI_PK, AI_PK being the primary
key. Is there any way I can instruct it to point to another column
(marked as UNIQUE)?

Thanks!

-- 
Vassilios Kountouriotis



More information about the odb-users mailing list