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

Vassilios Kountouriotis b.kountouriotis at gmail.com
Tue Sep 12 02:19:58 EDT 2017


Boris, thanks for your insight.

Unfortunately, I'm new to ODB and I am not sure how to do either.
Would it be possible to direct me to the relevant place in the
documentation?

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. I was looking for something like:

> #pragma db index("index_name") member(Column)

but for foreign key constraints.

Again, thanks for your time!


On Mon, Sep 11, 2017 at 5:22 PM, Boris Kolpackov
<boris at codesynthesis.com> wrote:
> 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



-- 
Vassilios Kountouriotis



More information about the odb-users mailing list