开发者

Yii migration update

开发者 https://www.devze.com 2023-02-20 00:41 出处:网络
In a migration, I want to add an order column which defaults to the ID of the column. I tried the following:

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')));
0

精彩评论

暂无评论...
验证码 换一张
取 消