Fixed relations being wiped out when saving

The code worked like this:

1. Delete old relations
2. Get related entities
3. Save old relations

If the entity hasn't retrieved relations until now, autoloader tried to
get related entities /after/ they were deleted.
This commit is contained in:
Marcin Kurczewski 2014-10-25 18:26:22 +02:00
parent f72b0216a5
commit 3dbb2b06be
2 changed files with 7 additions and 8 deletions

View file

@ -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

View file

@ -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