php - 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
解决方案
尝试使用asArray()
:
$data = EmployeeTasks::find()->with('employee')->asArray()->all();
推荐阅读
- javascript - 如何在 JSON 表单中添加日期值?[附上片段]
- react-native - React-Native-Video 在模态框内使用时不显示控件
- javascript - fs.WriteFile 在实际写入文件之前启动回调
- bash - Bash 脚本 - 从 Json 中删除重复的键值对
- java - 导入 sun.security.pkcs11 无法解决
- python - 单击 Python Selenium 中特定行上的表中的按钮
- c - 缓存阻塞实际上是如何提高性能的?
- c++ - 使用向量c ++进行二分搜索
- html - BootStrap 行内容在移动视图中粘在左侧
- javascript - 在 react 的 render 方法中调用的函数中运行 for 循环