relationManyToMany & inheritance

Forum for posting problems using QxOrm library

Re: relationManyToMany & inheritance

Postby QxOrm admin » Wed May 18, 2011 4:37 pm

You can download the patch here :
http://www.qxorm.com/version/QxOrm_1.1.6_BETA_03.zip

Don't forget to rebuild QxOrm library and your project ;)
QxOrm admin
 

Re: relationManyToMany & inheritance

Postby guparan » Thu May 19, 2011 7:30 am

Thanks, it works fine :D
guparan
 

Re: relationManyToMany & inheritance

Postby guparan » Thu May 19, 2011 1:35 pm

One more question,
For each Recipe, I have several Articles. But I also have a quantity, an amount and a tax.

How to link one Recipe to several Articles without forget the 3 numbers depending on each Article ?

These parameters cannot be in Article class because, for example, an Article can be sold more expensively than normal price for one and only one Receipt.

I tried to integrate them in a QxCollection<Article_ptr, article_details> with struct { int qty; float amount; float VAT; } article_details but I don't know how to map that :?
guparan
 

Re: relationManyToMany & inheritance

Postby QxOrm admin » Thu May 19, 2011 1:59 pm

I'm sorry but I don't understand what do you want exactly.
This is a database design question, not really a question about QxOrm library.

Perhaps you can ask in other forums like Hibernate or Subsonic to know how to resolve your database design problem with another ORM tool (or directly into database schema).
Then we will adapt the solution to QxOrm library...
QxOrm admin
 

Re: relationManyToMany & inheritance

Postby guparan » Mon May 23, 2011 7:28 am

I try to better explain my problem.

This is my Database :
Image


As you can see, I have an Extra table for each ManyToMany relation, but I also have informations wich can be differents for each relation.

Actually, each Receipt (TicketCaisse) class must have an Articles list but for each of these Articles, it must know the quantity, the amount and the VAT.

Does QxOrm provide this case ?
guparan
 

Re: relationManyToMany & inheritance

Postby QxOrm admin » Mon May 23, 2011 1:10 pm

Ok I understand your problem : you have extra-columns defined into your extra-table to manage your many-to-many relationship.

I have found this link to explain how this case works with Hibernate ORM :
http://www.mkyong.com/hibernate/hiberna ... nnotation/

Today, sorry, QxOrm library doesn't provide a feature to map those "extra-columns".
But this is interesting and will be developped in the next version...

I think the best solution would be :
1- Define another class to map all extra-columns (for example, a class "ReceiptArticle" in your case, with 3 properties : quantity, amount and TVA) ;
2- Then create a property class : "QList<ReceiptArticle_ptr>" in both "Receipt" and "Article" classes ;
3- Then, in your "qx::register_class<T>" function, use this new property with "t.relationManyToMany()" call.

What do you think about it ?
QxOrm admin
 

Re: relationManyToMany & inheritance

Postby QxOrm admin » Tue May 24, 2011 7:42 am

Maybe there is a solution with current version of QxOrm library !
I have not tested yet but maybe it works :

1- You have your 2 classes : "Receipt" and "Article"
2- Create another class : "ReceiptArticle" with 3 properties : quantity, amount and TVA
3- Instead of define "many-to-many" relation for both "Receipt" and "Article" classes, define relation of type "one-to-many" to "ReceiptArticle" class
4- Into your "ReceiptArticle" class, define 2 relations "many-to-one" to "Receipt" and "Article" classes

So you obtain something like this :
Code: Select all
"Article" class   [one-to-many]    <---->   [many-to-one]   "ReceiptArticle" class    [many-to-one]    <---->    [one-to-many]   "Receipt" class


To fetch all datas with 1 query, initialize a "ReceiptArticle" instance, put a Receipt id or an Article id and fetch with all relations.
You can test it if you want, I think it could work... ;)
QxOrm admin
 

Re: relationManyToMany & inheritance

Postby guparan » Wed Jun 01, 2011 8:55 am

Sorry for my (very) long silence.

I agree with your solution but trying to implement it, I have some problem with relationOneToMany.

I want to add this relation to Article and Receipt class, I write
Code: Select all
t.relationOneToMany(& Article::receipts_articles, "Receipt_Article_list", "IdArticle");

Code: Select all
t.relationOneToMany(& Receipt::receipts_articles, "Receipt_Article_list", "IdTicketCaisse");


But it doesn't compile.
Am I mistaking in implementation ?
Can you explain me the need of relationOneToMany 2nd argument ?

PS : I upgraded to 1.1.6, QX_REGISTER_ABSTRACT_CLASS is usefull ! ;)
guparan
 

Re: relationManyToMany & inheritance

Postby QxOrm admin » Wed Jun 01, 2011 10:21 am

For more information about relation one-to-many, you have the tutorial qxBlog :
* in english : http://www.qxorm.com/qxorm_en/tutorial.html#tuto_6
* in french : http://www.qxorm.com/qxorm_fr/tutorial.html#tuto_6

When you write : t.relationOneToMany(& Receipt::receipts_articles, "Receipt_Article_list", "IdTicketCaisse");
It means :
* argument n°1 "& Receipt::receipts_articles" : the property in your C++ class you want to map to a table in the database (this is a one-to-many relation, so here the property must be a container from stl, boost, Qt or QxOrm library)
* argument n°2 "Receipt_Article_list" : the property key (you can use this key with QxOrm introspection engine for example, and when the C++ property is not a container, this key is also the column name in the database)
* argument n°3 "IdTicketCaisse" : the property key that you have defined in the class associated by the relation (in your case, in the class "ReceiptArticle", you should have a C++ property of type "Receipt" with a property key "IdTicketCaisse")

What is your compilation error ?
Do you have tried to build qxBlog project ? If yes, it builds and executes without problem ?
QxOrm admin
 

Re: relationManyToMany & inheritance

Postby guparan » Wed Jun 01, 2011 12:50 pm

I fixed my error, just an inclusion problem.

Reading (for the X time) your qxBlog example, I am always a bit confusious because your article primary key and blog foreign key are the same (article_id).

Which of both is in relationOneToMany() ?
guparan
 

PreviousNext

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 34 guests