Reputation: 28762
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'
),
'', // condition
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?
Upvotes: 6
Views: 9945
Reputation: 437434
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')));
Upvotes: 8