2 回答
TA贡献2065条经验 获得超14个赞
这是因为ActiveQuery尝试使用 JOIN 从查询结果中删除重复的模型(例如,如果房子有 2 个所有者,则结果集中的房子数据将重复两次)。在你的情况下,如果你想从数据库中获取原始数据,你应该使用Query:
$dataSearch = (new Query())
->select(["number","DATE(reg_date) AS date","((value) > 100) AS result","info"])
->from(House::tableName())
->join("INNER JOIN", Owner::tableName(), Owner::tableName().'.number_ow= '.House::tableName().'.number_ow')
->andWhere([House::tableName().'.number_ow'=>$house->number_ow])
->andFilterWhere([House::tableName().'.space'=>$space])
->orderBy([House::tableName().'.reg_date'=>SORT_DESC,'info'=>SORT_ASC]);
$data = $dataSearch->all();
但是如果你真的需要ActiveQuery,你应该配置$indexBy为每一行返回唯一的 ID。
TA贡献1842条经验 获得超12个赞
将 andWhere 替换为 Where 检查此代码
$dataSearch = House::find()
->select(["number","DATE(reg_date) AS date","((value) > 100) AS result","info"])
->join("INNER JOIN", Owner::tableName(), Owner::tableName().'.number_ow= '.House::tableName().'.number_ow')
->where([House::tableName().'.number_ow'=>$house->number_ow])
->andFilterWhere([House::tableName().'.space'=>$space])
->orderBy([ClosedOperation::tableName().'.reg_date'=>SORT_DESC,'info'=>SORT_ASC]);
$data = $dataSearch->asArray()->all();
- 2 回答
- 0 关注
- 189 浏览
添加回答
举报