From e80af076a80a38d3bae3cd49f34be1e83064519f Mon Sep 17 00:00:00 2001 From: Azat Kashapov Date: Sat, 5 Aug 2023 08:02:23 +0300 Subject: [PATCH] Update Book.php --- modules/api/models/Book.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/api/models/Book.php b/modules/api/models/Book.php index 025bc25..7d852c8 100644 --- a/modules/api/models/Book.php +++ b/modules/api/models/Book.php @@ -29,7 +29,7 @@ * @property BookTag[] $bookTags * @property Series $series * @property Tag[] $tags - * @property Tag[]|null $tag_ids + * @property int[]|null $tag_ids */ class Book extends ActiveRecord { public $tag_ids; @@ -116,16 +116,15 @@ public function attributeLabels(): array { } public function afterSave($insert, $changedAttributes) { - if(array_key_exists('tags', $changedAttributes)) { - if (!$this->isNewRecord) { - $this->unlinkAll('tags', true); - } - foreach ($this->tag_ids as $tag_id) { - $tag = Tag::findOne($tag_id); - $this->link('tags', $tag); - } + if (!$this->isNewRecord) { + $this->unlinkAll('tags', true); } + foreach ($this->tag_ids as $tag_id) { + $tag = Tag::findOne($tag_id); + $this->link('tags', $tag); + } + if (array_key_exists('text', $changedAttributes)) { $this->saveTextToFs(); }