diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index e24e7ee2..8d780a45 100644 --- a/src/Dao/PostDao.php +++ b/src/Dao/PostDao.php @@ -257,9 +257,6 @@ class PostDao extends AbstractDao implements ICrudDao private function syncPostRelations(Post $post) { - $this->pdo->deleteFrom('postRelations')->where('post1id', $post->getId())->execute(); - $this->pdo->deleteFrom('postRelations')->where('post2id', $post->getId())->execute(); - $relatedPostIds = array_filter(array_unique(array_map( function ($post) { @@ -269,6 +266,8 @@ class PostDao extends AbstractDao implements ICrudDao }, $post->getRelatedPosts()))); + $this->pdo->deleteFrom('postRelations')->where('post1id', $post->getId())->execute(); + $this->pdo->deleteFrom('postRelations')->where('post2id', $post->getId())->execute(); foreach ($relatedPostIds as $postId) { $this->pdo diff --git a/src/Dao/TagDao.php b/src/Dao/TagDao.php index 2796cc58..17f9d4d8 100644 --- a/src/Dao/TagDao.php +++ b/src/Dao/TagDao.php @@ -188,11 +188,6 @@ class TagDao extends AbstractDao implements ICrudDao private function syncRelatedTagsByType(Tag $tag, array $relatedTags, $type) { - $this->pdo->deleteFrom('tagRelations') - ->where('tag1id', $tag->getId()) - ->where('type', $type) - ->execute(); - $relatedTagIds = array_filter(array_unique(array_map( function ($tag) { @@ -202,6 +197,11 @@ class TagDao extends AbstractDao implements ICrudDao }, $relatedTags))); + $this->pdo->deleteFrom('tagRelations') + ->where('tag1id', $tag->getId()) + ->where('type', $type) + ->execute(); + foreach ($relatedTagIds as $tagId) { $this->pdo