Reputation: 1095
This is my code:
$model= Prices::model()->findByPk($pk);
$model->status = 1;
$model->update(array('status'));
This update my row using the primary key, but how do I update a query without the pk in Yii. For instance:
How do I write this query:
update mytable set mycolumn = '1' where mycolumn1 ='2' and mycolumn2 = '3' and mycolumn3 = '4' ? Thx
Upvotes: 1
Views: 731
Reputation: 38502
Try this way to update your model using UpdateAll()
Prices::model()->updateAll(
array('mycolumn'=>1),'mycolumn1=:mycolumn1 AND
mycolumn2=:mycolumn2 AND mycolumn3=:mycolumn3',
array(':mycolumn1'=>2,':mycolumn1'=>3,':mycolumn1'=>4)
);
Upvotes: 0
Reputation: 611
Did you tried first string like this?
$model= Prices::model()->findByAttributes(
array(
'mycolumn1' => 2,
'mycolumn2' => 3,
'mycolumn3' => 4
)
);
$model->mycolumn = 1;
$model->update(array('mycolumn'));
Upvotes: 1