Composite PKs and FKs

Open discussion on QxOrm library

Composite PKs and FKs

Postby ncremonesi » Fri Mar 20, 2015 1:25 pm

Hello, I am thinking about using QxORM in a huge C++ project managed by a SQLite database.

I also tried other ORMs and so I have many questions. The first is, is QxORM able to manage a composite Primary Key that also references a composite (too) Foreign Key?
ncremonesi
 
Posts: 1
Joined: Fri Mar 20, 2015 1:21 pm

Re: Composite PKs and FKs

Postby qxorm » Fri Mar 20, 2015 3:50 pm

Hello,

Yes it should work !
To define a composite key, I would recommend to :
- read this post in the FAQ : http://www.qxorm.com/qxorm_en/faq.html#faq_101
- try the project sample located in the ./test/qxBlogCompositeKey/ directory of QxOrm package
- try QxEntityEditor : this app can be helpful to know how to implement some features of QxOrm library : first, design your database schema with a tool dedicated to your SGBD (SQLite Manager for SQlite database for example), then open QxEntityEditor and run the import process ==> you will see how to implement your model.

Then, about the composite foreign key, you have the solution here :
http://stackoverflow.com/questions/2158 ... m-is-a-man

Code: Select all
namespace qx
{
template <> void register_class(QxClass<secondtable> & t)
{
   t.id(&secondtable::m_id, “second_table _key|first_table_key”);
   t.data(&secondtable::m_text, "second_table_text");
   qx::IxSqlRelation * pRelation = t.relationManyToOne(&secondtable::m_firsttable, “first_table”);
   pRelation->getDataMember()->setName("first_table_key");
}
}

As you can see, you can define your relation with another key (first_table), which is not the same key as your primary key (first_table_key). And then, just put the correct name of your relation using pRelation->getDataMember()->setName() method.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron