Sunday, 15 July 2012

php - Yii CDbCriteria adding unwanted alias -



php - Yii CDbCriteria adding unwanted alias -

i need run next statements cdbcriteria in yii :

select `tbl_products`.`id` `tbl_products` inner bring together `tbl_producttags` on `tbl_products`.`id` = `tbl_producttags`.`product_id` inner bring together `tbl_tags` on `tbl_producttags`.`tag_id` = `tbl_tags`.`id`

what i've tried far :

$criteria = new cdbcriteria(); $criteria->select= '`tbl_products`.`id`'; $criteria->join ='inner bring together `tbl_producttags` on `tbl_products`.`id` = `tbl_producttags`.`product_id`' . ' inner bring together `tbl_tags` on `tbl_producttags`.`tag_id` = `tbl_tags`.`id`'; $products = products::model()->findall($criteria);

but me next error :

sql statement: sqlstate[42s22]: column not found: 1054 unknown column 'tbl_products.id' in 'field list'. sql statement executed was: select tbl_products.id tbl_products t inner bring together tbl_producttags on tbl_products.id = tbl_producttags.product_id inner bring together tbl_tags on tbl_producttags.tag_id = tbl_tags.id

the problem :

it's because of cdbcriteria added unwanted alias name t after tbl_products

how can prepare it?

use

$criteria = new cdbcriteria(); $criteria->select= '`youralias`.`id`'; $criteria->alias="youralias"; $criteria->join ='inner bring together `tbl_producttags` on `tbl_products`.`id` = `tbl_producttags`.`product_id`' . ' inner bring together `tbl_tags` on `tbl_producttags`.`tag_id` = `tbl_tags`.`id`'; $products = products::model()->findall($criteria);

the alias name of table. if not set, means alias 't'

php mysql yii

No comments:

Post a Comment