0

我正在尝试获取每个商店的评论数,并且我真的停留在这一步。
有可能做到吗,怎么做?

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 );
    }
4

1 回答 1

0

您需要的是CounterCache 行为

http://book.cakephp.org/3.0/en/orm/behaviors/counter-cache.html

于 2015-10-17T11:29:31.923 回答