PDA

View Full Version : Can I obtain original foreign key value (or table row) from QSqlRelationalTableModel?



stevebakh
20th May 2010, 14:07
Hi,

I'm using QSqlRelationalTableModel but unfortunately, it removes the foreign key fields and replaces them with the displayColumn value from the related model.

Example:

Table "Foo" has a column called bar_id which references table "Bar". Foo is represented by a QSqlRelationTableModel and has the Bar table set as a relation. Any records fetched from the Foo relational model will no longer have a column/field named "bar_id". Instead, the column name will resemble the display column name, set when attaching the relation.



My question is: How can I get the rest of the data from Bar? I can't do a filter+select on the Bar table, because I don't have access to bar_id anymore. Is there some way of obtaining the original foreign key, or can I get the related row from the Bar table in another way?

Any help would be greatly appreciated.

Thanks

Al_
2nd April 2011, 16:40
see http://www.qtcentre.org/threads/28602-Method-to-read-foreign-key-values-from-QSqlRelationalTableModel for similar question and possible workaround.