简体   繁体   中英

Using JOIN in NotORM

Been trying the following code

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

from http://sql-cross-queries.freexit.eu/dibi/notorm to create a JOIN statement, but to no avail. Am I missing out on anything?

I have reports(timestamp, incident_id, location id), incident(incident_id, incident_desc, location_id), and location(location_id, location_name). I am trying to get timestamp, incident_name, and location_name by joining reports, incident, and location. So I used the following statement:

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

but it's not returning anything. The following statement, though:

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

returns reports.

Try this, not 100% sure but worth a try.

$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"); 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM