Count in contain Cakephp 3
问题 I have a table Post and this has a has-many association with a table Stars . I can get all the associated data using: $this->Posts->find()->contain(['Stars']); That works well. But I want to count the Stars. I have tried this but its not working: $this->Posts->find->contain([ 'Stars' => function($q) { return $q->select(['total' => $q->func()->count('Stars.post_id')]); } ]); //I've also tried this ... ...$q->select(['total' => "COUNT(Stars.post_id)"]); ... //Also fail This does not return the