Yii2 - hasOne with leftJoin

时间:2016-02-19 19:34:02

标签: yii yii2

我正在尝试将 leftJoin 添加到 hasOne 方法,但似乎它无效。主表中的数据是存在的,但不是来自连接表。代码:

public function getUser()
    {
        return $this->hasOne(UserKeys::classname(), ['id' => 'userKey_id'])
            ->leftJoin('users', 'users.id = userKeys.user_id');
    }

1 个答案:

答案 0 :(得分:0)

您应该使用 viaTable 而不是 leftJoin

let data = [{app: "test1", key: 1}, {app: "test2", key:2}, {app: "test1", key:3}, {app: "test2", key:3}]

let checkArr = ["test1", "test2", "test3"]

let result = [].concat(...checkArr.map(ch => data.filter(da => da.app === ch)))

console.log(result)