I have a qsqlrelationaltablemodel setup with a QSqlRelation to another table working great. Now I would like to lookup additional columns for that row on the related table. How do I accomplish this?
Example tables:
city ('id', 'name', 'state_id')
state ('id', 'name', 'capital')
what I have so far:
model = QtSql.QSqlRelationalTableModel()
model.setTable('city')
model.setRelation(1, QtSql.QSqlRelation("state", "id", "name"))
model.select()
Which would give me a row like:
| 1 | 'San Francisco' | 'California' |
Now I would like to lookup the capital in the state model, from the city table. How do I do this? My understanding of setRelation is it takes the id from the main_table at column X and replaces it with the mapped column, but I don't want to alter the state table. I've looked into the QSqlRecord and QSqlRelation, but I seem to be missing something.
Thanks!
Aucun commentaire:
Enregistrer un commentaire