我有一个表Thingsies
,其中列id
,data1
,otherTableId
,otherTableRowId
。我需要最后两列而不是外键列,因为根据Thingy
我想要的信息类型有不同。
otherTableId
引用表id
中的OtherTables
,该表本身包含名为id
和tableName
的列。这些tableNames
是其他表格的名称,例如OtherTable1
,OtherTable2
otherTableRowId
中的Thingies
列引用了id
给出的OtherTable
中的otherTableId
。 OtherTables
本身有更多数据。 Thingies与其中一个OtherTables
中的条目之间存在一对一的对应关系。因此,Thingies中的行数是所有OtherTables
中的总行数。 (这是不好的设计吗?)
我想在QTableView
中显示Thingies,其中包含id
,data1
和data2
的列,其中data2
以编程方式从{{{}}生成1}}和otherTableId
。我该怎么办?
感谢。
答案 0 :(得分:0)
我想我已经解决了这个问题。我正在使用QSqlQueryModel
,其查询是一组select语句的并集,每个OtherTable
一个。每个select语句都必须以某种方式使用特殊表达式以某种方式合并(例如,连接)每个OtherTable
的唯一数据,因此对我来说至少对OtherTables
表没用。