在NotORM中使用JOIN

时间:2012-11-27 14:32:24

标签: php sql notorm

尝试以下代码

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

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

我有报告(时间戳,incident_id,位置ID),事件(incident_id,incident_desc,location_id)和位置(location_id,location_name)。我试图通过加入报表,事件和位置来获取时间戳,incident_name和location_name。所以我使用了以下声明:

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

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

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

返回报告。

2 个答案:

答案 0 :(得分:0)

试试这个,不是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"); 

答案 1 :(得分:0)

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