0

I'm trying to get total no of products from products table where product.store_id = store.id in cakephp to shoq store owner his total products in his store and i'm using containable behavior to get this by this query

 $stores = $this->Store->find('all', array(
        'contain' => array(
           'Product' => array(
           'conditions' => array('product.store_id = store.id')
          'fields' => array('COUNT(*) AS count')
        ) 
)));

Store HABM products product HABM Store

3 tables

stores products products_stores

But i'm getting empty array of products on view

[Product] => Array
                (
                )

i know ,i'm not getting product(id, name, other features), but total no of products should be in this array. Or kindly tell me the way to get total products of specific store.

sorry for bad English.

coder
  • 156
  • 3
  • 23
  • 1
    possible duplicate of [CakePHP Model: COUNT(\*) in Containable](http://stackoverflow.com/questions/2308087/cakephp-model-count-in-containable) – bish Dec 29 '14 at 12:59
  • i saw that before post my question. i tried to do in that way but my problem was not solved.let me do one more try to do in that way. – coder Dec 29 '14 at 13:06
  • @bish that is for hasMAny association , but i have HABM association Products HABM Stores and Stres HABM Products, so in this way i found a way to add countercache var $actsAs = array('CounterCacheHabtm'); but my store model already has public $actsAs = array('Containable'); so what you say now – coder Dec 29 '14 at 13:14
  • Use both: `$actsAS = array('Containable','CounterCacheHabtm');` – AgRizzo Dec 29 '14 at 13:21

0 Answers0