查询列值相等的地方

时间:2019-07-05 10:47:09

标签: orm cakephp-3.x

我有以下查询:

$drivers = TableRegistry::getTableLocator()->get('Drivers');
$driver = $drivers->find()->where(['user_id' => $userId])->first();
return $drivers->find()->where(['user_id' => $userId])
    ->contain([
        'Users',
        'Championships' => [
            'Races' => [
                'Results' => [
                    'strategy' => 'select',
                    'queryBuilder' => function (Query $query) use ($driver) {
                        return $query->where(['driver_id' => $driver->id]);
                    }
                ]
            ]
        ]
    ])
    ->first();

我想知道是否可以将它们组合在一起。我认为这是有可能的:

$drivers = TableRegistry::getTableLocator()->get('Drivers');
return $drivers->find()->where(['user_id' => $userId])
    ->contain([
        'Users',
        'Championships' => [
            'Races' => [
                'Results' => [
                    'strategy' => 'select',
                    'queryBuilder' => function (Query $query) {
                        return $query->where(['driver_id' => 'Drivers.id']);
                    }
                ]
            ]
        ]
    ])
    ->first();

但是,它会引发Column not found: 1054 Unknown column 'Drivers.id' in 'where clause'错误。

是否可以合并,我该怎么做?

0 个答案:

没有答案