Inheritance of abstract classes

Forum for posting problems using QxOrm library

Inheritance of abstract classes

Postby jomoifen » Tue Jan 31, 2012 12:08 pm

Hi everyone,

I want to create a PostgresQL Database from my class structure which contains an abstract class "message". I registered the class as abstract using QX_REGISTER_ABSTRACT_CLASS(Message) and made the constructor a pure virtual function. However, when iterating over all classes as described in "http://www.qxorm.com/qxorm_en/faq.html" , section "How to build SQL schema (create and update tables) based on C++ persistents classes registered into QxOrm context" I can't find a way to skip my abstract class. Therefore I always get a table "message" although the fields are already contained in the subclasses. Is there a way to query the classes I get by calling qx::QxClassX::getAllClasses() whether they are abstract or not so I can skip all abstract classes?

Thanks
jomoifen
 
Posts: 2
Joined: Tue Jan 31, 2012 12:00 pm

Re: Inheritance of abstract classes

Postby QxOrm admin » Tue Jan 31, 2012 1:00 pm

Hi,

To filter some classes (abstract or not), you can use the notion of property bag (http://www.qxorm.com/doxygen/html/class ... y_bag.html) :

1- In your qx::register_class<T>() function, add something like this :
Code: Select all
namespace qx {
template <> void register_class(QxClass<MyClass> & t)
{
   t.setPropertyBag("NOT_PERSISTABLE", "1");
  //...
}}


2- Then, when you iterate over all classes :
Code: Select all
for (long k = 0; k < pAllClasses->count(); k++)
{
   IxClass * pClass = pAllClasses->getByIndex(k);
   QString sProp = pClass->getPropertyBag("NOT_PERSISTABLE").toString();
   if (sProp == "1") { continue; }
   //...
}
QxOrm admin
 

Re: Inheritance of abstract classes

Postby jomoifen » Mon Feb 06, 2012 2:37 pm

Hi,

thank you for the quick response. I managed to solve the issue with the abstract classes, however another problem occurred. I have two classes (Team and member) which have an n-to-n relation.

In header:
typedef boost::shared_ptr<Member> MemberPtr;
typedef QVector<MemberPtr> VectorMemberPtr;
typedef boost::shared_ptr<Team> TeamPtr;
typedef QVector<TeamPtr> VectorTeamPtr;


In Member.cpp:
t.relationManyToMany(& Member::m_teams, "VectorTeamPtr", "Member_Team", "member_id", "team_id");

In Team.cpp
t.relationManyToMany(& Team::m_members, "VectorMemberPtr", "Member_Team", "team_id", "member_id");

However, when the tables are created I miss the Member_Team table needed for the n_to_n relation as it is not defined as a class itself. How can I make sure that this table is also created automatically?
jomoifen
 
Posts: 2
Joined: Tue Jan 31, 2012 12:00 pm

Re: Inheritance of abstract classes

Postby QxOrm admin » Mon Feb 06, 2012 3:05 pm

Hi,

I managed to solve the issue with the abstract classes, however another problem occurred.

Please create a new thread on this forum each time you have a new problem or a new question.

I have two classes (Team and member) which have an n-to-n relation...... How can I make sure that this table is also created automatically?

In your function to create your own SQL schema, you iterate over all classes, then for each class, you iterate over all datamembers.
For each class, you have also to iterate over all relations ;)
You can find an example here : http://www.qxorm.com/qxorm_fr/resource/ ... chema.html
And if you execute the function qx::QxClassX::dumpSqlSchema() in your program, you will see all tables related to a relation many-to-many (you must use QxOrm 1.2.2, the last version, to see it).

Here is the code you are looking for :
Code: Select all
// Create extra-table from relations (for example, many-to-many relation needs an extra-table)
for (long l = 0; (pDataMemberX && (l < pDataMemberX->count_WithDaoStrategy())); l++)
{
   IxDataMember * p = pDataMemberX->get_WithDaoStrategy(l);
   if (isValid_SqlRelation(p) && (p != pId) && (bCreateTable || (p->getVersion() >= lVersion)))
   {
      QString sqlExtraTable = p->getSqlRelation()->createExtraTable();
      if (sqlExtraTable.isEmpty()) { continue; }
      sql += sqlExtraTable + "\n";
   }
}
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 6 guests

cron