【问题标题】:Using JOIN in NotORM在 NotORM 中使用 JOIN
【发布时间】:2012-11-27 14:32:23
【问题描述】:

一直在尝试以下代码

$notorm->table()->select("table.*, table2.column, table2.table3.column2"); 

从http://sql-cross-queries.freexit.eu/dibi/notorm创建JOIN语句,但无济于事。我错过了什么吗?

我有报告(时间戳、事件 ID、位置 ID)、事件(事件 ID、事件描述、位置 ID)和位置(位置 ID、位置名称)。我试图通过加入报告、事件和位置来获取时间戳、事件名称和位置名称。所以我使用了以下语句:

$notorm->reports()->select("reports.*, incident.incident_id, incident.location.location_id");

但它没有返回任何东西。但是下面的声明:

$notorm->reports()->select("reports.*");

返回报告。

【问题讨论】:

  • 请描述您的问题。

标签: php sql notorm


【解决方案1】:

试试这个,不是 100% 肯定,但值得一试。

$notorm->reports()->join("reports", "LEFT JOIN incident ON reports.incident_id = incident.incident_id")
->join("reports", "LEFT JOIN location ON reports.location_id = location.location_id")
->select("reports.timestamp, incident.incident_desc, location.location_name"); 

【讨论】:

    【解决方案2】:

    在您的 table 定义中,必须有一个字段名称 table2_id 存在

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多