【问题标题】:Qt: viewing data from tables with foreign key columns pointing to multiple other tablesQt:从具有指向多个其他表的外键列的表中查看数据
【发布时间】:2011-08-02 22:18:35
【问题描述】:

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

我想在包含iddata1data2 的列的QTableView 中显示Thingies,其中data2 是从otherTableIdotherTableRowId 以编程方式生成的。我应该如何进行?

谢谢。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 2019-02-18
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多