How to customize the generated classes to add relations

Forum for posting problems using QxEntityEditor

How to customize the generated classes to add relations

Postby jackson » Mon Mar 24, 2014 9:41 am

We want to develop an application where all changes are database driven. That means, on any model change the database will be changed first.
After that, an import of the changed DB into EntityEditor will be made. No changes are made to the imported model, so we are able to reimport and export at any time.
The export to an existing project will overwrite only the generated classes, but not the customized.

As the generation of relations by the EntityEditor does not work yet, I want to make a workaround and add the relations by my own in the customized classes.
To do that, I inherited from the generated class with all attributes and all data members. Now I add only the relations to the customized classes.
The aim is, to get rid of the customized classes as soon the generation of relations in EntityEditor will work.

My Problem at this point is, that the foreign key will be defined twice. First as simple attribute in the parent class and second as relation in my child class.

Now my Question:
- exists a more elegant way to modify/extend the data members of a generated class than inherit from the generated class?
- is it possible to remove the data member of the parent with the foreign key in the child class? How?
- alternatively is it possible to overwrite the data member of the parent class in the child class? How?

Maybe you have already some examples with customizations of generated classes?

Thanks jackson
jackson
 
Posts: 4
Joined: Thu Mar 20, 2014 7:22 am

Re: How to customize the generated classes to add relations

Postby qxorm » Mon Mar 24, 2014 11:03 am

Hi,

The export to an existing project will overwrite only the generated classes, but not the customized.

By 'customized', you mean write it in the 'custom' directory generated by the QxEntityEditor export process ?
The first purpose of this directory is to implement triggers and validators.
But yes, you can use it if you want to create inherited classes...

exists a more elegant way to modify/extend the data members of a generated class than inherit from the generated class?

I would say : no !
To define a relationship, you need a link to another class :
* 1-n & n-n : you need a collection (std:vector, QList, qx::QxCollection, etc..., no matter the type of collection) ;
* n-1 : you need a pointer or smart-pointer to another class.

I don't see another way to define this link than creating a new class (inherited or not from a generated class).

is it possible to remove the data member of the parent with the foreign key in the child class? How?

No : you can add and access to a qx::IxDataMember instance, but not remove it.

alternatively is it possible to overwrite the data member of the parent class in the child class? How?

Yes, using the introspection engine of QxOrm library, you can access to a qx::IxDataMember instance, and modify it.
More details in the FAQ here : http://www.qxorm.com/qxorm_en/faq.html#faq_190
And more details about qx::IxDataMember class here : http://www.qxorm.com/doxygen/html/class ... ember.html

I think you will have a problem only with n-1 relationships.
Because with 1-n relationships, there is no data member generated automatically.

Anyway, the best solution for you would have a QxEntityEditor import process which works with relationships.
I will try to provide you as soon as possible a new import plugin (working with PostgreSQL in your case)...
qxorm
Site Admin
 
Posts: 477
Joined: Mon Apr 12, 2010 7:45 am

Re: How to customize the generated classes to add relations

Postby qxorm » Fri Mar 28, 2014 10:18 pm

Here is a first try to improve the import process for PostgreSQL database.
You can download QxEntityEditor_1.1.4_BETA_06 (portable win 32) here :
http://www.qxorm.com/version/QxEntityEd ... in_32b.zip

There are 2 new fields in the import by ODBC screen :
* Database type : select your database type ("Generic" means the old process, "PostgreSQL" uses specific queries to get database structure) ;
* Delete all entities in the namespace before importing : checkbox to delete entities automatically.

Using "Database type" equals to "PostgreSQL" :
* schema should be managed correctly : you could have a same table name in different schema for example ;
* relationships should be imported.

There is certainly some things to improve, but this is a first try and you can test it...
qxorm
Site Admin
 
Posts: 477
Joined: Mon Apr 12, 2010 7:45 am


Return to QxEntityEditor - Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron