Yii Migration Update

When migrating, I want to add an order column that defaults to the column id. I tried the following:

$this->update(
 'item',  // table
  array(  // columns
    'item_order'=>':item_id'
  ), 
  '',     // condition
  array(  // parameters
    ':item_id'=>'item_id'
  )
);

But that just gives all ID 0. (I'm not very surprised, since I assume it is trying to use a row as opposed to a column name).

Any way to do this without manually building SQL?

+5
source share
1 answer

Wrap the column name in CDbExpression, in which Yii should include it in the received query without saving:

$this->update('item', array('item_order'=> new CDbExpression('item_id')));
+6
source

All Articles