Hello everyone.I’m a newer using YII.Here is my problem as the title.Respect your’s help!TH’X .
I create 2 table(mysql):product(InnoDB) and product_description(InnoDB),and they relative by product_id,when i get the data from product,it’s work,but when i get the data about them with the relational,it’s not work.Here is my code,respect your’s help,Thanks again!
class product extends CActiveRecord
{
…
public function relations()
{
return array(‘product_descriptions’ => array(self::HAS_MANY, ‘Product_Description’, ‘product_id’)));
}
…
function searchByKeyword()
{
$dataProvider = new CActiveDataProvider(‘Product’);
$criteria = new CDbCriteria();
$criteria->select = ‘t.ID
,t.product_quantity
,pd
.product_name
’;
$criteria->join = ‘LEFT JOIN product_description
pd ON pd
.product_id
=t.ID’;
$criteria->condition = ‘pd
.product_name
= \‘IBM\’’;
$criteria->limit = 10;
$count = Product::model()->count($criteria);
$pages = new CPagination($count);
$pages->pageSize=10;
$pages->applyLimit($criteria);
$dataProvider->criteria = $criteria;
return $dataProvider;
}
}
}
[exception.CDbException] exception ‘CDbException’ with message ‘Active record “product” is trying to select an invalid column “product_description.product_name
”. Note, the column must exist in the table or be an expression with alias.’