Sjaak Rusma
Sjaak Rusma

Reputation: 1434

Updating record with condition Yii

I am trying to update a row in the database that has a certain value as 'position' in Yii.

Now I can use the update() method. But this does not allow me to specify a condition. I am trying to avoid CDbCriteria and native sql to keep my code clean. Does anyone has an advice to update a single record in yii with a condition?

Thanks in advance,

Upvotes: 0

Views: 8028

Answers (2)

Uladzimir Pasvistselik
Uladzimir Pasvistselik

Reputation: 3921

Did you see the method updateAll ?

CActiveRecord::updateAll($attributes, $condition='', $params=array())

Updates records with the specified condition.

Parameters:
array $attributes - list of attributes (name=>$value) to be updated mixed
$condition - query condition or criteria
array $params parameters to be bound to an SQL statement

Upvotes: 1

SoniCoder
SoniCoder

Reputation: 4174

updateAll is a method in CActiveRecord, and it lets you specify conditions http://www.yiiframework.com/doc/api/1.1/CActiveRecord#updateAll-detail

Upvotes: 1

Related Questions