我真的没有得到为什么当我尝试返回特定列时这种急切的加载不起作用。此代码正常工作
$user=User::where('userName', $userName)
->with('points')
->with('examstaken')
->with('question')
/*->with(array('points'=>function($query){
$query->select('id','points');
}))*/
->get();
此代码不磨牙
$user=User::where('userName', $userName)
/*->with('points')*/
->with('examstaken')
->with('question')
->with(array('points'=>function($query){
$query->select('id','points');
}))
->get();
不起作用的意思是,"点"在第一个正确返回值时不会返回任何值。
有什么想法怎么了?
这是我的用户模型中的关系
public function points()
{
return $this->hasMany('AppPoints','user_id');
}
谢谢..
ok解决了它。看来我必须通过USER_ID,外键,然后它们将起作用。将其作为答案发布,因为其他人可能会得到帮助:)
$user=User::where('userName', $userName)
/*->with('points')*/
->with('examstaken')
->with('question')
->with(array('points'=>function($query){
$query->select('user_id','points');
}))
->get();