-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
I have a model with translatable behaviour and
public function getTranslations()
{
return $this->hasMany(ModelI18n::className(), ['id' => 'id']);
}
When I do:
$translation = $mainModel->translate('eng');
$translation->name = 'New name';
$mainModel->save();
$mainModel->translations has duplicate entries
This code loops over existing translations and calls link() which causes duplicate related objects:
// TranslateableBehavior.php
/**
* @return void
*/
public function afterSave()
{
/* @var ActiveRecord $translation */
foreach ($this->owner->{$this->translationRelation} as $translation) {
$this->owner->link($this->translationRelation, $translation);
}
}
If $this->owner->{$this->translationRelation} returns related objects, they are already linked. When you create new translations, you have to link them yourself.
Metadata
Metadata
Assignees
Labels
No labels