class Category extends MvcModel {
var $table = '{prefix}' . BMSPC_TABLE_PREFIX . 'categories';
var $display_field = 'name';
var $order = 'Category.name ASC';
var $has_many = array('Product');
}
class Product extends MvcModel {
var $table = '{prefix}' . BMSPC_TABLE_PREFIX . 'products';
var $includes = array( 'Category' );
var $display_field = 'style_name';
var $order = 'Product.style_name ASC';
var $has_and_belongs_to_many = array(
'Category' => array(
'join_table' => '{prefix}' . BMSPC_TABLE_PREFIX . 'product_categories',
'fields' => array('id', 'name')
)
);
public function after_find($object) {
}
}
I have a category, product and product_categories tables. Trying to show count of Products that belong to a Category but array of products is coming empty.
class Category extends MvcModel { var $table = '{prefix}' . BMSPC_TABLE_PREFIX . 'categories'; var $display_field = 'name'; var $order = 'Category.name ASC'; var $has_many = array('Product');
}
class Product extends MvcModel { var $table = '{prefix}' . BMSPC_TABLE_PREFIX . 'products'; var $includes = array( 'Category' ); var $display_field = 'style_name'; var $order = 'Product.style_name ASC'; var $has_and_belongs_to_many = array( 'Category' => array( 'join_table' => '{prefix}' . BMSPC_TABLE_PREFIX . 'product_categories', 'fields' => array('id', 'name') ) );
}
I have a category, product and product_categories tables. Trying to show count of Products that belong to a Category but array of products is coming empty.