$winnerBid = Bids::model()->find($criteria);
Model has next relations:
public function relations() {
return array(
'item' => array(self::BELONGS_TO, 'Goods', 'item_id'),
'room' => array(self::BELONGS_TO, 'Rooms', 'room_id'),
'seller' => array(self::BELONGS_TO, 'RoomPlayers', 'seller_id'),
'buyer' => array(self::BELONGS_TO, 'RoomPlayers', 'buyer_id'),
);
}
When I am trying to save:
$this->seller->current_item++;
$this->seller->wins++;
$this->seller->save();
I am getting error:
Indirect modification of overloaded property Bids::$seller has no effect (/var/www/auction/www/protected/models/Bids.php:16)
But it was everything fine at another server? How to fix it? Or override php directives? Any ideas? TNX
The problem here is that
$seller
is not a "real" property (Yii implements properties on its Models by using the magic__get
method), so in effect you are trying to modify the return value of a function (which has no effect). It is as if you tried to do:I 'm not sure about the status of this behavior on different PHP versions, but there is an easy workaround you can use:
I was also having the error message "Yii Indirect modification of overloaded property" when trying to massively manipulate attributes using the CActiveRecord attributes property.
Then, I discovered another method to overcome this issue, in a case where the magic method is related to an object variable which contains an array take a look: you create an AUXILIARY ARRAY in which you put the original and the new values (sometimes one wants to REPLACE a value related to one of the keys, and these methods are not satisfactory). And AFTERWARDS use an assignation, which works like the reference. For example: