Reputation: 1603
I'm trying to assign a value to the property with behavior, but no matter what value I pass to $this->owner->property
the model assigns this number "127" to the property and saves it. I can't figure out where this number comes from.
namespace common\behaviors;
use yii\db\ActiveRecord;
use yii\base\Behavior;
class MyBehavior extends Behavior
{
public function events()
{
return [
ActiveRecord::EVENT_BEFORE_INSERT => 'test',
ActiveRecord::EVENT_BEFORE_UPDATE => 'test',
];
}
public function test()
{
$this->owner->property = 444;
}
}
If I populate this property htrough the web form on frontend the model saves correct value.
I added property
to model's rules but that doesn't make any difference.
Upvotes: 0
Views: 492
Reputation: 1603
Shame on me, I made so stupid mistake while creating SQL table :( I assigned tinyint type to property
field, that's why it always saves 127 - the maximum allowed value for this type of field.
Upvotes: 1