cakephp3.1:无法限制关联中加载的字段

时间:2015-12-30 10:51:27

标签: cakephp-3.1

我执行以下查询:

$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语句,将检索到的字段限制为idowner_idfirstnamelastname,但它返回以下结果:

'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

0 个答案:

没有答案