I know that there are some similar quesiton here, but they are all related to using
Model->find('all');
But this is not what I do, I do:
Model->find('list');
This is what makes the difference between this worker and does not work.
Given a product group, I want to find all the brands in this group and the quantity of each brand.
It sounds simple enough, here is what I did:
$fields = array('Product.brand','COUNT(`Product`.`brand`) AS brand_count') $brand_data = $this->Product->find('list',array( 'fields'=>$fields, 'conditions'=>$conditions, 'recursive'=>0, 'group' => 'Product.brand' )); debug($brand_data);
In this, I tell him to give me an array, where the keys are Product.brand and the values ββare COUNT(Product.brand)
I get the following:
Array ( [Brand A] => [Brand B] => [Brand C] => )
When I expect this:
Array ( [Brand A] => 534 [Brand B] => 243 [Brand C] => 172 )
It works if I do all instead of list , but it just gives me a much more complex array that can be drilled. I use everything perfectly, I just wanted to know at first if there is a reason why it does not work on the list ?
source share