Updating multiple rows in database

Hello there,

How example i have table mytable and model (CActiveRecord) for that table and

i want to update one column value of one record in that table how to do that in proper way?

for example i know:




UPDATE mytable SET myfield = new value WHERE other_field = 1 



for that i use




Mytable::model()->updateAll($attributes,$condition,$params);



and other situotation how to realize smting like this?




UPDATE mytable

    SET myfield = CASE other_field

        WHEN 1 THEN 'value'

        WHEN 2 THEN 'value'

        WHEN 3 THEN 'value'

    END

WHERE id IN (1,2,3)



if i want to update a lot of rows with different conditions and diferent values in one sql?

thank you for your time :)


UPDATE mytable

    SET myfield = CASE other_field

        WHEN 1 THEN 'value'

        WHEN 2 THEN 'value'

        WHEN 3 THEN 'value'

    END

WHERE id IN (1,2,3)




Try this


mytable::model()->updateByPk(array(1,2,3), 

     array('myfield' => new CDbExpression(

                   "CASE other_field WHEN 1 THEN 'value'  WHEN 2 THEN 'value'  WHEN 3 THEN 'value'  END")

      )

);



updateAllByAql()

what is that? i cant find anything about that :expressionless:

oh, no this function~

you can use createCommand() to do it!

Thank you all for reply.

thank you