This is not the exact database I am working with, but a simplified version of it showing my main problem. So, let's assume we have the following SQL Database structure:
Table A - a list of employees:
id - primary key
name - string describing a persons name
Table B - a list of offices:
id - primary key
location - string describing an office location of a person from table a
Table C - a list of company cars:
id - primary key
car - string describing the type of car of a person from table a
Table A_B_Relation - each person can belong to multiple offices:
a_id - foreign key to table A.id
b_id - foreign key to table B.id
Table A_C_Relation - each person can own several company cars:
a_id - foreign key to table A.id
c_id - foreign key to table C.id
Table A - a list of employees:
id - primary key
name - string describing a persons name
Table B - a list of offices:
id - primary key
location - string describing an office location of a person from table a
Table C - a list of company cars:
id - primary key
car - string describing the type of car of a person from table a
Table A_B_Relation - each person can belong to multiple offices:
a_id - foreign key to table A.id
b_id - foreign key to table B.id
Table A_C_Relation - each person can own several company cars:
a_id - foreign key to table A.id
c_id - foreign key to table C.id
To copy to clipboard, switch view to plain text mode
The displayed overview of people and cars they own/offices they belong to should look like the attached image.
The main problem that bugs me is: How to set up the QSqlRelationalTableModel properly?
When I set it up using table A as main table then I fail to find a way of displaying the car / office names - QSqlRelation only allows me to display the IDs of each role, or did I miss something in the docs about using it for this kind of thing? Currently I think that I will have to write my own model - am I correct there? It is certainly possible to simply use a QSqlTableModel and set a custom sql query on it which would deliver the data in a way that I could display it as I want using standard Qt classes.
But then there comes the problem with editing the displayed data in a proper way. I assume that safely editing the fields would require a custom delegate, no?
I am a bit puzzled if I am trying the correct approach on this issue.
Bookmarks