yii 义与条件有一个关系

hfwmuf9z  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(123)

我的代码中有一个hasone关系,

public function getDevice(){
    return $this->hasOne(UserDevice::className(),['user_id' => 'id'])->where(['is_latest'=>true]);
}

在我的查询中,我尝试获取用户详细信息。

$query = User::find();
  $query->joinWith('device')->all();

如果我使用getDevice时没有where条件,我将获得所有用户。但是如果我在getDevice中添加where条件,我将获得具有设备详细信息的用户。是否有任何方法可以列出具有检查的所有用户。也就是说,我需要列出所有用户,这些用户在设备表中是否具有详细信息

zbsbpyhn

zbsbpyhn1#

我已经在我的关系中使用了这个,它起作用了。

public function getDevice(){
    return $this->hasOne(UserDeviceInfo::className(),['user_id' => 'id'])->orOnCondition(['is_latest' =>1]);
}

相关问题