Decrease value of a column in all rows using ActiveRecord


As it doesnt work this way:




        $update = Post::model();


could you point me to an alternative way to increase or decrease value of numeric column using ActiveRecord?

Any help appreciated

updateCounters() :) Welcome to the forums!


	 * Postprocessing after the record is saved


	protected function afterSave()





	protected function afterDelete()




Not tested, but it should work.

Maybe you should take a look here:

greetz from Germany


1 Like

thanx, somehow i didnt noticed that method before:)

and one more thing about this:

if i need some column to have a value of another column, what’s the trick to do that with AR?

for example following sql

update myTable set column=otherColumn

thanx in advance

update(array(‘column’=>CDbExpression(‘otherColumn’))); might work, I haven’t tested though.