2020-03-31 16:06:18 81次浏览 0条回答 0 悬赏 10 金钱

我的表对象 Order 设置了两个属性分别用了别名 selluserbuyuser

<?php
public function getSelluser()
{
    return $this->hasOne(User::className(), ['uid' => 'selluserid'])->from(['selluser' => User::tableName()]);
}
public function getBuyuser()
{
    return $this->hasOne(User::className(), ['uid' => 'buyuserid'])->from(['buyuser' => User::tableName()]);
}
?>

在ActiveRecord里做了软删除

<?php
public static function find()
{
    $query = new ActiveQuery(get_called_class());
    $field = static::tableName(). '.is_del';
    return $query->softDelete([$field => static::STATUS_ACTIVE]);
}
?>

现在问题来了,当我做关联查询的时候

<?php
Order::find()->joinWith("buyuser")->joinWith("selluser")->joinWith("product")->andWhere(['buyuserid'=>$user->uid])->andWhere(['process'=>$process])->all();
?>

报错,提示

"name": "Database Exception",
"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 't_user.is_del' in 'where clause'\nThe SQL being executed was: SELECT `t_order`.* FROM `t_order` LEFT JOIN `t_user` `buyuser` ON `t_order`.`buyuserid` = `buyuser`.`uid` LEFT JOIN `t_user` `selluser` ON `t_order`.`selluserid` = `selluser`.`uid` LEFT JOIN `t_article` `product` ON `t_order`.`articleid` = `product`.`id` WHERE (`t_order`.`is_del`=10) AND (`buyuserid`=272) AND (`process`='1') AND (`t_user`.`is_del`=10) AND (`t_user`.`is_del`=10) AND (`t_article`.`is_del`=10) LIMIT 8",

找不到 t_user 表的 is_del,t_user 表的 is_del 是我做的软查询每次 find 都会自动插入条件 is_del,但是我用了关联的别名查询,把原本的 t_user 变成了 selluser,导致找不到 t_user 表的 is_del报错,请问怎么解决?谢谢

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
谦
实习生

广东阳江

注册时间:2020-03-31
最后登录:2020-03-31
在线时长:0小时11分
  • 粉丝0
  • 金钱0
  • 威望0
  • 积分0

热门问题