laravel文档对于ORM的预载入内容很少,使用中发现貌似只有预载入条件限制才起作用
$users = User::with(array('posts' => function($query)
{
$query->where('title', 'like', '%first%');
}))->get();
而对于select/lists这些总是返回空
$company = Company::with(array('users' => function($query)
{
$query->select('id');
}))->select('id', 'type', 'logo', 'name', 'profile', 'city', 'email', 'phone', 'website', 'weibo', 'tags')->find($id);
返回的$company的json一直是
{
"status": "success",
"data": {
"id": 1,
"type": 0,
"logo": "1428470471LLnfH.jpg",
"name": "123",
"profile": "",
"city": "",
"email":
"[email protected]",
"phone": "123456",
"website": "",
"weibo": "",
"tags": "",
"user_count": 3,
"thumb_logo": "http://120.25.210.83/upload/companies/thumb/1428470471LLnfH.jpg",
"users": []
}
}
users总是为空,但是换成$query->where才能返回数据
要怎么使select也在预载入起作用?
以及如果users数组里面还包含了tweets数组,怎么做tweets的预载入?