Skip to content

Commit

Permalink
Fix detach behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Loban committed Dec 18, 2015
1 parent 27a38bb commit 3364e59
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/TranslatedBehavior.php
Expand Up @@ -51,19 +51,23 @@ class TranslatedBehavior extends BaseTranslatedBehavior
*/
public function events()
{
$beforeDelete = function() {
$this->owner->unlinkAll($this->translateRelation, true);
};
$afterSave = function() {
$this->owner->link('currentTranslate', $this->getTranslation());
};
return [
ActiveRecord::EVENT_BEFORE_DELETE => $beforeDelete,
ActiveRecord::EVENT_AFTER_INSERT => $afterSave,
ActiveRecord::EVENT_AFTER_UPDATE => $afterSave,
ActiveRecord::EVENT_BEFORE_DELETE => 'eventBeforeDelete',
ActiveRecord::EVENT_AFTER_INSERT => 'eventAfterSave',
ActiveRecord::EVENT_AFTER_UPDATE => 'eventAfterSave',
];
}

public function eventAfterSave()
{
$this->owner->link('currentTranslate', $this->getTranslation());
}

public function eventBeforeDelete()
{
$this->owner->unlinkAll($this->translateRelation, true);
}

/**
* Returns the translation model for the specified language.
* @param string|null $language
Expand Down

0 comments on commit 3364e59

Please sign in to comment.