updateCounters() bug?

I noticed weird behaviour. I am using updateCounters() to update a row in mysql. I have:


$upd = Model::model()->updateCounters(

array('field1'=>'1','field2'=>'2','field3'=>'1')

.....

)

What I noticed is that if field1 and field2 do not exist in the Model table but field3 exists than updateCounters updates only field3 and does not fail bur returns 1 row updated.

Is this the expected behaviour because I would expect this to fail with a proper error/exception that the first two fields do not exist.

Has anybody seen this before?

Regards,

bettor

If you’ll look at the CDbCommandBuilder’s method createUpdateCounterCommand(), then you’ll see:




foreach($counters as $name=>$value)

{

    if(($column=$table->getColumn($name))!==null)

    {

        $value=(int)$value;

        if($value<0)

            $fields[]="{$column->rawName}={$column->rawName}-".(-$value);

        else

            $fields[]="{$column->rawName}={$column->rawName}+".$value;

    }

}



So it is an expected behavior. You can check if columns exist manually using CDbTableSchema.getColumn() method.

Thanks andy_s