Page 1 of 1

1-1 Relationships

PostPosted: Mon Jun 20, 2016 6:48 pm
by Kasuax
I can't find any examples on how to create 2 tables with a 1-1 relationship. It sounds simple but I can't figure out what combination of settings in the EntityEditor makes both the C++ generated code happy and the postgres sql generator happy. I can modify either side after generating these output files but I feel as though I shouldn't have to... Help, Tutorial, Example? Do they share the same key name?

Re: 1-1 Relationships

PostPosted: Mon Jun 20, 2016 7:50 pm
by qxorm
Hello,

In most cases, you should use a n-1 relationship instead of a 1-1 relationship.
A 1-1 relationship is a very specific case where 2 tables share the same id : for example, imagine a person table and a user table and you want that these 2 tables share the same id, then you can use a 1-1 relationship.

I can't figure out what combination of settings in the EntityEditor makes both the C++ generated code happy and the postgres sql generator happy. I can modify either side after generating these output files but I feel as though I shouldn't have to...

What is your error exactly ?
What do you have to change after exporting your project ?

Re: 1-1 Relationships

PostPosted: Tue Jun 21, 2016 3:00 am
by Kasuax
Ok good, I'm on the right track.

I did use the same key name across objects. The problem is, what should the relationship name be called? If I re-use the key name as the relationship name with the other table then the sql is happy and the foreign keys are correct too. For some reason the primary key name is not included in the {field name|relationship name} validation so it can be reused to make sql happy at the expense of the C++ code becoming invalid. Reusing that field name causes obvious naming issues with the generated class objects.

I think what the UI needs is a way to specify what the foreign key field name is in a 1-1 relationship.

For reference, I'm using the postgres exporter.

At the moment I think my solution will be to make the C++ generated code settled and fix up the foreign keys myself.

Re: 1-1 Relationships

PostPosted: Tue Jun 21, 2016 10:27 am
by qxorm
For some reason the primary key name is not included in the {field name|relationship name} validation so it can be reused to make sql happy at the expense of the C++ code becoming invalid. Reusing that field name causes obvious naming issues with the generated class objects.

I will try to reproduce the issue to fix it for the next release.

Re: 1-1 Relationships

PostPosted: Mon Dec 12, 2016 9:39 am
by qxorm
Should be fixed with QxEntityEditor 1.2.1 : for changes log and download, please go to QxOrm download web page : https://www.qxorm.com/qxorm_en/download.html.