Best way to work with hierarchical data

Forum for posting problems using QxOrm library

Best way to work with hierarchical data

Postby Davita » Mon Mar 26, 2012 7:28 pm

Hi :)
I wanted to know if QxOrm supports hierarchical data, for example, if a row has a reference of another row in same table. How should I do mapping, how should I query, anything I should consider when working with hierarchical data would be welcome :)

Thanks
Davita
 

Re: Best way to work with hierarchical data

Postby Davita » Mon Mar 26, 2012 8:40 pm

I think I found out how to do that. I updated blog class (from official samples) as shown below

Code: Select all
namespace qx {
template <> void register_class(QxClass<blog> & t)
{
   t.id(& blog::m_id, "blog_id");

   t.data(& blog::m_text, "blog_text");
   t.data(& blog::m_dt_creation, "date_creation");

[b]   t.relationManyToOne(& blog::m_parent, "parent_id");
   t.relationOneToMany(& blog::m_children, "list_blog", "parent_id");
[/b]   t.relationManyToOne(& blog::m_author, "author_id");
   t.relationOneToMany(& blog::m_commentX, "list_comment", "blog_id");
   t.relationManyToMany(& blog::m_categoryX, "list_category", "category_blog", "blog_id", "category_id");
}}


Till now, it works. Is this a recommended approach or does it have any drawbacks? Can I use this solution in production?

Thanks :)
Davita
 

Re: Best way to work with hierarchical data

Postby QxOrm admin » Tue Mar 27, 2012 7:49 am

Hi,

Till now, it works. Is this a recommended approach or does it have any drawbacks? Can I use this solution in production?

Yes, it should work without problem !

I just recommend to use smart-pointers for your blog::m_parent and blog::m_children C++ properties.
For example, with boost smart-pointers (you could use Qt smart-pointers if you prefer) :
Code: Select all
boost::shared_ptr<blog> m_parent;
QList< boost::shared_ptr<blog> > m_children;
QxOrm admin
 

Re: Best way to work with hierarchical data

Postby Davita » Tue Mar 27, 2012 7:55 am

Thank you very much :)
Davita
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 6 guests

cron