我有以下型号的
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
键。
您可以尝试以下操作,因为我不确定with
方法是否与find
一起工作:
ParentModel::with('children')->where(array('ParentModel_pmk_id' => 1))->get();