Qt:从具有指向多个其他表的外键列的表中查看数据

时间:2011-08-02 22:18:35

标签: database qt relational-database qtableview model-view

我有一个表Thingsies,其中列iddata1otherTableIdotherTableRowId。我需要最后两列而不是外键列,因为根据Thingy我想要的信息类型有不同。
otherTableId引用表id中的OtherTables,该表本身包含名为idtableName的列。这些tableNames是其他表格的名称,例如OtherTable1OtherTable2 otherTableRowId中的Thingies列引用了id给出的OtherTable中的otherTableIdOtherTables本身有更多数据。 Thingies与其中一个OtherTables中的条目之间存在一对一的对应关系。因此,Thingies中的行数是所有OtherTables中的总行数。 (这是不好的设计吗?)

我想在QTableView中显示Thingies,其中包含iddata1data2的列,其中data2以编程方式从{{{}}生成1}}和otherTableId。我该怎么办?

感谢。

1 个答案:

答案 0 :(得分:0)

我想我已经解决了这个问题。我正在使用QSqlQueryModel,其查询是一组select语句的并集,每个OtherTable一个。每个select语句都必须以某种方式使用特殊表达式以某种方式合并(例如,连接)每个OtherTable的唯一数据,因此对我来说至少对OtherTables表没用。