zuck
4th August 2009, 10:51
Hi guys!
I need to map database "many-to-many" and "one-to-many" relations into my Qt code. I didn't found an "official" Qt class for this feature so my question is: what's the best approach, in your opinion, for implementing a complete database-relationship support?
My idea is to create two new classes:
1) QSqlAdvancedRelation which inherits from QSqlRelation and maps all three main relation types ("one-to-one", "one-to-many", "many-to-many").
2) QSqlAdvancedRelationalTableModel which inherits from QSqlRelationalTableModel and uses one or more instances of QSqlAdvancedRelation class.
For many-to-many relation, the idea is to use the relation table name as a virtual field name in the original table which value is a list of QModelIndex of the related table and vice versa:
Original table <- Relationship table -> Related table
For one-to-many relation, the approach is simpler: the relation returns the list of QModelIndex of the related model filtered by a where clause.
Original table <- Related table
What do you think about this approach?
I need to map database "many-to-many" and "one-to-many" relations into my Qt code. I didn't found an "official" Qt class for this feature so my question is: what's the best approach, in your opinion, for implementing a complete database-relationship support?
My idea is to create two new classes:
1) QSqlAdvancedRelation which inherits from QSqlRelation and maps all three main relation types ("one-to-one", "one-to-many", "many-to-many").
2) QSqlAdvancedRelationalTableModel which inherits from QSqlRelationalTableModel and uses one or more instances of QSqlAdvancedRelation class.
For many-to-many relation, the idea is to use the relation table name as a virtual field name in the original table which value is a list of QModelIndex of the related table and vice versa:
Original table <- Relationship table -> Related table
For one-to-many relation, the approach is simpler: the relation returns the list of QModelIndex of the related model filtered by a where clause.
Original table <- Related table
What do you think about this approach?