我正在尝试将 leftJoin 添加到 hasOne 方法,但似乎它无效。主表中的数据是存在的,但不是来自连接表。代码:
public function getUser()
{
return $this->hasOne(UserKeys::classname(), ['id' => 'userKey_id'])
->leftJoin('users', 'users.id = userKeys.user_id');
}
答案 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)