Page 1 of 1

Creating a realtionship with multiple columns

PostPosted: Wed Jun 25, 2014 10:12 pm
by arolin
I have two entities:

Entity1:
    Entity1_Id
    Token
    SubToken

    Time

Entity2:
    Entity2_Id
    Token
    SubToken

    Description

Token and sub-token essentially make for a single key into entity2 so there is an N-1 relationship between Entity1 and Entity2 for the combined Token and Subtoken property. I am not sure how to model this correctly as it appears to me that the relationships point to the primary key of the target entity.

Thanks!

Re: Creating a realtionship with multiple columns

PostPosted: Thu Jun 26, 2014 7:25 am
by qxorm
Hello,

Token and sub-token essentially make for a single key into entity2

So if I understand well, token + sub-token should be your primary key in entity2, and you should remove the Entity2_Id property.
token + sub-token becomes a 'multi-columns primary key' (or composite key).

About QxOrm library and composite keys, there is :
- more details in the FAQ here : http://www.qxorm.com/qxorm_en/faq.html#faq_101
- a sample project in ./test/qxBlogCompositeKey/ directory of QxOrm package

And to define a composite key in QxEntityEditor, you have to :
- token + sub-token is just a single property (instead of 2 properties) ;
- in the 'Column name' field of entity params window (or property params window), put the following value : Token|SubToken