Order by, row alias count for example in Pagination CakePHP 3.x, by linking a join table

As I can in cakephp 3.x I can sort the results by a row that has a count, because I do not see the form, something very similar in CakePHP 2.x works without problem. What is missing to be able to do the same in CakePHP 3.x ..?

HTML ctp

<?= $this->Paginator->sort('count_users',_('N° Users')); ?>

Controller

    $this->Licensees->schema()
        ->addColumn('count_users', [
            'type' => 'integer',
        ]);
    $this->Licensees->aliasField('count_users');

    $where = [
        'recursive'=>-1,
        'fields' => [
           'Licensees.id',
           'Licensees.name',
           'Licensees.created',
           'Licensees.modified',
           'Licensees__count_users' => 'count(LicenseesUsers.licensees_id)'
         ],
        'sortWhitelist' => ['name','count_users','created','modified'],
        'join' => [
            'LicenseesUsers' => [
                'table' => 'licensees_users',
                'type' => 'LEFT',
                'conditions' => [
                    'LicenseesUsers.licensees_id = Licensees.id'
                ],
            ],
        ],
        'group' => 'Licensees.id'
    ];

     // Set pagination
    $this->paginate = $where;

    // Get data
    $licensees = $this->paginate($this->Licensees);

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image