Skip to content

Commit

Permalink
Update Book.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ufaboy committed Aug 5, 2023
1 parent 0bfa1e9 commit e80af07
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions modules/api/models/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit e80af07

Please sign in to comment.