剛剛用Yii 的AR 寫的很開心,
下了這個
[sourcecode language=’php’]
$criteria=new CDbCriteria;
$criteria->condition=’products.id=:ID AND products_info.language_id=:languageID’;
$criteria->params=array(‘:ID’=>$_GET[‘id’], ‘:languageID’ => $this->_lang_id );
$criteria->order = ‘products_content.content_orders ASC’;
$model = Products::model()->with( ‘products_info’, ‘products_content’ )->find( $criteria );
[/sourcecode]
一直出現
CDbCommand 無法執行 SQL 陳述: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘products.id’ in ‘where clause’
想說怪了…
再看了一下 sql log
[sourcecode language=’text’]
543 Query SELECT `t`.`id` AS `t0_c0`, `products_info`.`products_id` AS `t1_c0`, `products_info`.`language_id` AS `t1_c1`, `products_info`.`name` AS `t1_c2`, `products_info`.`content` AS `t1_c3`, `products_content`.`id` AS `t2_c0`, `products_content`.`products_id` AS `t2_c1`, `products_content`.`language_id` AS `t2_c2`, `products_content`.`content_name` AS `t2_c3`, `products_content`.`content_value` AS `t2_c4`, `products_content`.`content_orders` AS `t2_c5` FROM `products` `t` LEFT OUTER JOIN `products_info` `products_info` ON (`products_info`.`products_id`=`t`.`id`) LEFT OUTER JOIN `products_content` `products_content` ON (`products_content`.`products_id`=`t`.`id`) WHERE (products.id=’1′ AND products_info.language_id=’1′) ORDER BY products_content.content_orders ASC
[/sourcecode]
發現Products model 變成t 了
想說很怪
再去看了一下 1.1 CHANGELOG
發現了這段..
The alias name for the primary table in a relational AR query is changed to be ‘t’ (Qiang)
好吧乖乖的把products.id改成t.id