In a migration, I want to add an order column which defaults to the ID of the column. I tried the following:
$this->update(
'item', // table
array( // columns
'item_order'=>':item_id'
),
'', // c开发者_高级运维ondition
array( // parameters
':item_id'=>'item_id'
)
);
But this just gives everything ID 0. (I'm not really surprised, since I'm guessing it's trying to use the string as opposed to the column name).
Any way to get this done without manually constructing SQL?
Wrap the column name in a CDbExpression
, which instructs Yii to include it in the resulting query unescaped:
$this->update('item', array('item_order'=> new CDbExpression('item_id')));
精彩评论