relationManyToMany & inheritance

Forum for posting problems using QxOrm library

Re: relationManyToMany & inheritance

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

Sorry, I meaned "confiused" and not "confusious" (bad english). :oops:
guparan
 

Re: relationManyToMany & inheritance

Postby QxOrm admin » Wed Jun 01, 2011 3:06 pm

In qxBlog tutorial, when I write the register function for author class :
Code: Select all
t.relationOneToMany(& author::m_blogX, "list_blog", "author_id");


The string "author_id" is the key you have defined into the blog class (and not the author class).
QxOrm library needs this information to retrieve the property associated by the relation one-to-many in the blog class ===> "author_ptr m_author;" defined into blog class.
QxOrm admin
 

Re: relationManyToMany & inheritance

Postby guparan » Mon Jun 06, 2011 10:12 am

My mapping seems correct but when I fetch_all_with_all_relations(receipt_article_list), Receipts and Articles are created but not fetched with relations : I can access to Receipts properties but not Receipt::Customer properties.

I tried to fetch_all(receipt_article_list) with a receipt_id property and to call receipt_article::receipt::setId(receipt_id) to then fetch_by_id_with_all_relation(receipt_article::receipt) as you explained but I get an error while I kept relations.

I can do this if I remove relations but I cannot yet access to Receipt::receipts_articles.

So, how to fetch all datas keeping relations ?
guparan
 

Re: relationManyToMany & inheritance

Postby QxOrm admin » Mon Jun 06, 2011 12:54 pm

All methods inside "qx::dao" namespace are limited to 2 tables when you use relationships.

So with this design (I think it is your database design) :
Code: Select all
"Article" class   [one-to-many]    <---->   [many-to-one]   "ReceiptArticle" class    [many-to-one]    <---->    [one-to-many]   "Receipt" class

=> If you execute "fetch_all_with_all_relations" using "ReceiptArticle" class => you will fetch all properties of "Article" class and "Receipt" class (but not relations).

If you add something like this in your design (see "Class1" and "Class2", I think you have your "Customer" class here) :
Code: Select all
"Class1" [one-to-many] <----> "Article" class [one-to-many] <----> [many-to-one] "ReceiptArticle" class [many-to-one] <----> [one-to-many] "Receipt" class <----> [one-to-many]  "Class2"

"Class1" and "Class2" classes will be not fetched because there is more than 2 tables starting from "ReceiptArticle" class.

This is a limitation of QxOrm library today.
You can workaround this issue defining a view into your database.
Or you can write your own SQL query using QtSql module of Qt library.
QxOrm admin
 

Previous

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron