2016-05-03 38 views
0

我有以下型號Laravel5預先加載不工作

class ParentModel extends Model 
{ 
    public function children() 
    { 
    return $this->hasMany('App\Model\Student', 'parent_id'); 
    } 
} 

class Student extends Model 
{ 

} 

當我使用ParentModel::find(1)->children,它給出正確的結果。 但是,當我使用ParentModel::with('children')->find(1)時,結果數組包含一個值爲空數組的children鍵。

回答

0

你可以嘗試,因爲我不知道,with方法將沿着邊工作,find如下:

ParentModel::with('children')->where(array('ParentModel_pmk_id' => 1))->get();