hi i have followed the
http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/
with table structure :
Products
__________
productID
Name
enable
ProductsCategories
__________________
categoryID
productID
categories
____________
categoryID
name
parentID
model code is :
class Product extends CActiveRecord {
public $categoriez = array();
public $categories_search;
.....
public function relations() {
return array(
'categories' => array(self::MANY_MANY, 'Category', 'Productscategories(productID,categoryID)'),
....
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('productID', $this->productID, true);
$criteria->compare('Name', $this->productName, true);
$criteria->with = array('categories');
$criteria->compare('categories.category.categoryName', $this->categoriez, true);
}
class Productscategories extends CActiveRecord
{
...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'product' => array(self::BELONGS_TO, 'Products', 'productID'),
'category' => array(self::BELONGS_TO, 'Categories', 'categoryID'),
);
}
class Category extends CActiveRecord {
...
public function relations() {
return array(
'products' => array(self::MANY_MANY, 'Product', 'Productscategories(categoryID,productID)'),
);
}
...
and i m getting error :
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'categories.category.categoryName' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT `t`.`productID`) FROM `products` `t` LEFT OUTER JOIN `Productscategories` `categories_categories` ON (`t`.`productID`=`categories_categories`.`productID`) LEFT OUTER JOIN `categories` `categories` ON (`categories`.`categoryID`=`categories_categories`.`categoryID`) WHERE (categories.category.categoryName=:ycp0)
please guide what i m missing here .