我执行以下查询:
$sites = $this->Sites->find('all')
->select(['id', 'name'])
->contain([
'Users' => function ($q) {
return $q->select(['id', 'owner_id', 'firstname', 'lastname']);
},
])
->matching('Users', function ($q) use($owner_id)
{
return $q->where([
'Users.owner_id' => $owner_id
]);
})
->all();
因此,我在select()
关联中插入Users
语句,将检索到的字段限制为id
,owner_id
,firstname
和lastname
,但它返回以下结果:
'items' => [
(int) 0 => object(App\Model\Entity\Site) {
'id' => (int) 7,
'name' => 'the site',
'orders' => [],
'users' => [
(int) 0 => object(App\Model\Entity\User) {
'id' => (int) 49,
'owner_id' => (int) 42,
'firstname' => 'Ed',
'lastname' => 'Gavin',
'username' => 'EdG',
'password' => '$2y$10$jHN7/mLwkh7O.aOHVmAeK.PnY9IrT/tTpcKlH25Il0yLtveE6.Onu',
'email' => 'ed.gavin@yopmail.com',
'phone' => '',
'role' => 'owner',
'active' => (int) 1,
'token' => '8cf196e6b45e972fbfec11eb7b80748d',
'origin' => '',
'_joinData' => object(App\Model\Entity\SitesUser) {
您能否告诉我为什么select()
不尊重Users
?