首页 > 解决方案 > Yii2 rest api相关数据失败

问题描述

我试图返回相关数据但失败了

所以在我的控制器中我有

 $query = EmployeeTasks::with('employee')->find()->all();

return ["data"=>$query]

在我的 EmployeeTasks 中,我有详细的关系,例如

    public function getEmployee()
      {
       return $this->hasOne(CasualEmployees::className(), ['id' => 'employee_id']);
     }

但是返回的数据没有员工数据,即使应该有

我哪里错了?

$query 的转储有

[{name:'paint', created_at:1532508029....}] it doesnt have employee

标签: phpyii2

解决方案


尝试使用asArray()

$data = EmployeeTasks::find()->with('employee')->asArray()->all();

推荐阅读