0

I execute the following query:

$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();

So I insert a select() statement in Users association to restrict the retrieved fields to id, owner_id, firstname and lastname but it returns the following result:

'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) {

Can you tell me why the select() is not respected for Users?

fralbo
  • 2,534
  • 4
  • 41
  • 73

0 Answers0