在CakePHP3上构建查询

时间:2015-10-16 08:03:51

标签: cakephp-3.1

我正在试图获得每个商店的评论数量,我真的坚持这一步 是否可以这样做,以及如何做到?

public function display()
    {


        $this->loadModel('Shops');
        $shoplist=$this->Shops->find('all')->order(['title' => 'DESC', 'id' => 'ASC'])->contain([
            'Comments' => function ($q) {
                return $q->select('id')->where(['published' => 1])->count();
            }]);;

             $this->set('shoplist', $shoplist );
    }

1 个答案:

答案 0 :(得分:0)