OmgDef / yii2-multilingual-behavior

Yii2 port of the yii-multilingual-behavior.
146 stars 60 forks source link

setAttributes doesn't work on save #83

Open sergeizhukov opened 4 years ago

sergeizhukov commented 4 years ago

Hello! I have some question. I make update Event row and the next code is works:

$m = Event::find()->multilingual()->where(['id' => $id])->one();
$m->title = $fd['title'];
$m->save();

But

$m = Event::find()->multilingual()->where(['id' => $id])->one();
$m->setAttributes($fd);
$m->save();

Doesn't save.

$m = Event::find()->multilingual()->where(['id' => $id])->one();
$m->attributes = $fd;
$m->save();

Also doesn't save. Is it correct behaviour?

$m = Event::find()->multilingual()->where(['id' => $id])->one();
foreach ($fd as $key => $val) {
    $m->{$key} = $val;
}
$m->save();

This is again works and save.

OmgDef commented 4 years ago

Hi! I guess you didn't mention the title attribute in your validation rules in the Event model

sergeizhukov commented 4 years ago

Hi! I guess you didn't mention the title attribute in your validation rules in the Event model

You are right. It were dynamically add rules and wasn't this attribute on core model. Thanks!