PDA

View Full Version : QSqlRelationalTableModel



marvin
19th November 2008, 21:37
is it posible to use QSqlRelationalTableModel to relate one column in source table to multiple columns in destination table? For instance, if inf first table you have:


ID | NAME | AGE
1 | John | 10

and second:


ID | MOTHER | FATHER
1 | Anne | Bob

to get the table:

ID | NAME | AGE | MOTHER | FATHER
1 | John | 10 | Anne | Bob

model->setRelation replaces the column, while i'd like to add them.

wysota
19th November 2008, 22:13
The first question is whether the design of your database is correct. You could safely merge those two tables into a single one. As for the relational table model, it can't do what you want. You could implement a proxy that would merge two tables or create a view in your database and use QSqlTableModel or use QSqlQueryModel to fetch both tables. Just remember the latter is read-only.

marvin
19th November 2008, 22:29
The first question is whether the design of your database is correct. You could safely merge those two tables into a single one. As for the relational table model, it can't do what you want. You could implement a proxy that would merge two tables or create a view in your database and use QSqlTableModel or use QSqlQueryModel to fetch both tables. Just remember the latter is read-only.

tnx, i can't merge the tables, those were just for example, but using QSqlQueryModel solved my problem