I have two tables with the following structure:
product table :
name
category_id
product_category table:
name
id
I am use yii framework And I want show categories and 2 product every category. ProductCategory.php model relation :
public function relations() {
return array(
'products' => array(self::HAS_MANY, 'Product', 'category_id'),
);
}
I am use this code :
$criteria = new CDbCriteria();
$criteria->with = array('products'=>array('limit'=>2));
$dataProvider = new CActiveDataProvider('productCategory', array(
'criteria' => $criteria));
The above code show all categories and all product but I want show all categories and 2 (limit 2) product every category.
this code Just not working ('limit' is Effectless) :
$criteria->with = array('products'=>array('limit'=>2));
My main goal is to show category and 2 product every category ?