Tables:
-Incidents
--references locations thru location_id
-Locations
--references areas thru area_id
-Areas
每个区域都有位置,事件可能发生在任何位置。
如何设置关系,以便我可以 Eloquent 地抓取某个区域或位置中的所有事件?
我还必须在事件表中引用 area_id 吗?
最佳答案
您也可以执行嵌套关系查询。
例如:
Incidents::with(array('location', function($q) use ($areaId) {
return $q->where('area_id', $areaId);
}))->get();
查看 http://laravel.com/docs/eloquent#eager-loading 下的“预先加载约束”
关于mysql - 数据关系模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22761927/