update with query build

hi, im having troubles with query builder

im ok with select command but with update i can’t get it how to use it to produce:

"UPDATE users SET money = money-1 WHERE id = 1 LIMIT 1"

how can i make it using query builder?


I have always used the db->createCommand(‘UPDATE users SET money = money-1 WHERE id = 1 LIMIT 1’)->execute(); for that but this issue seems interesting…

Have you tried putting the table name in front?

$command->update('users', array(

    'users.money'=>'users.money - 1',

), 'id=:id', array(':id'=>1));

not tried yet but i think it will not work, because it will be passed as string


$command->update('users', array(

    'users.money'=>new CDbExpression('users.money - 1'),

), 'id=:id', array(':id'=>1));

Thanks Gustavo :)

thanks, that is what i need ;)

I need a update query with joins. Can anyone help for this?