1. I notice that QxBlog sample has no foreign key restrict, I can modify blog_id in comment table to any value which is not existed in blog table. How to create table with foreign key in QxOrm?
qxBlog tutorial uses
qx::dao::create_table<T>() function to create a prototype (or a quick example).
For a real application, I don't recommend to use
qx::dao::create_table<T>() function : it must be used only to create a prototype with SQLite.
I strongly recommend to build your SQL schema with a tool provided by your SGBD (
SQLite Expert or
SQLite Manager for example in your case).
But if you prefer, you can also create automatically your own SQL schema using introspection engine of QxOrm library, here is the FAQ to do it :
http://www.qxorm.com/qxorm_en/faq.html#faq_230Then, it is your choice
You can consider that all relationships
one-to-many and
many-to-one need a foreign key.
Or if you want to have foreign key only for specifics relations, you can use the notion of
property bag (adding some meta-data to your relation) :
viewtopic.php?f=2&t=81#p370If I create table with sql in SQLite Expert, how to map the restrict to my code?
The mapping doesn't change in your C++ code, because it's your choice and your design to add or not foreign key constraint in your SQL schema.
From a C++ point of vue, it's the same thing.
You can just add some meta-informations using the notion of
property bag if you want...