CakePHP自定义选择

时间:2016-04-14 22:56:03

标签: cakephp cakephp-3.0

如何在cakePHP 3中选择这样的选项?

SELECT v.* 
from 
    user u, residents r, user_has_vehicles uv, vehicles v
where
    u.id = r.user_id
    and u.id = uv.user_id
    and uv.vehicle_id = v.id
    and r.residencial_id = 1

它只返回来自residencial_id = 1的车辆的记录:

17  Renault Logan   Prata   EDS1234

我做了类似的事情:

$users = $this->User->find()
                        ->select(['id'])
                        ->matching('Residents', function ($q) {
                                return $q
                                ->select(['user_id'])
                                ->where(['Residents.residencial_id' => 1]);
                        })
                        ->contain(['UsersHasVehicles.Vehicles']);

但它返回的数据远远超过我的需要。

0 个答案:

没有答案