Saveattributes() On Records Without Primary Key

In Advert table ID is primary key. considering this code:

$specialAds = Advert::model()->findAll(array(

	'condition'=>'type=:special_ad and expiration_date < NOW()',

	'select'=>'type, leaf',

	'limit' => 100,




In above code don’t save attributes with given values. because ID in select condition is not set.

If select changed as following:

'select'=>'id, type, leaf',

attributes values will save truly. what’s the reason?

Because AR record relies on PK while saving.

You can use updateAll if you need to update records based on some other conditions.