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' => '[email protected]',
                '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?

3
  • Possible duplicate of CakePHP 3. Containable select Commented Dec 30, 2015 at 13:07
  • @ndm yes possible, and I'm going to test to disable autoFields. Thanks. Commented Dec 30, 2015 at 16:32
  • @ndm. That was the reason. Thanks. Commented Dec 30, 2015 at 16:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.