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?
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')));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With