Yii Framework Forum: increment & decrement in query builder - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

increment & decrement in query builder Rate Topic: -----

#1 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 27 September 2011 - 01:42 PM

problem described here http://www.yiiframew...-query-builder/

increment in query builder should be simple like update, or it not worth it

Yii::app()->db->commandBuilder->createUpdateCommand( 
                '{{table}}', 
                array( 
                    'counter' => new CDbExpression( 'counter + :counter' , array(':counter'=>1))
                    ), 
                new CDbCriteria(array(
                    "condition" => "id = :id" , 
                    "params" => array(
                        "id"=>1
                    )
                ))
            )->execute();


query builder rocks ;D

it makes our live easy, and our queries "short" :lol:
0

#2 User is offline   Lexxtor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 24-September 12

Posted 22 April 2014 - 07:14 AM

There is a shoter way:

User::model()->updateCounters(['points'=>$this->points], 'id=:id',[':id'=>$this->id]);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users