我有这样的表:
Account(...)
Country(...)
Region(...)
Station(id, name, lat, lng, ...)
Route(id, name, description, account_id, country_id, region_id, ...)
Trace(id, route_id, length, direction, t1, t2, ...)
TraceNode(id, lat, lng, route_id, trace_id, station_id)
TraceNode.station_id可以为空。
当我获取路由对象时,我想尽可能多地加载信息,所有跟踪,所有跟踪节点......
$route = Route::with(array('account', 'account.country','country', 'region', 'traces', 'traces.nodes', 'traces.nodes.station'))->findOrFail($request->input('id'));
但是我得到异常告诉我函数addEagerConstraint()失败,因为object为null(在这种情况下,station_id为null)。
我现在这样做的方式是:
$route = Route::with(array('account', 'account.country','country', 'region', 'traces', 'traces.nodes'))->findOrFail($request->input('id'));
foreach($route->traces as $trace)
foreach($trace->nodes as $node)
if( $node->isStation() )
$node->load('station');
如何判断laravel是否跳过了station_id为NULL的跟踪节点?