Skip to content

Commit

Permalink
relationships: fixed invalidating cache after persist & before flush [c…
Browse files Browse the repository at this point in the history
…loses #386]
  • Loading branch information
hrach committed Apr 10, 2020
1 parent 84ca3f3 commit 8f98094
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Relationships/OneHasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function doPersist()
$this->isModified = false;
$this->collection = null;
$this->getRelationshipMapper()->clearCache();
$this->relationshipMapper = null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use NextrasTests\Orm\Author;
use NextrasTests\Orm\Book;
use NextrasTests\Orm\DataTestCase;
use NextrasTests\Orm\Helper;
use NextrasTests\Orm\Publisher;
use NextrasTests\Orm\TagFollower;
use Tester\Assert;
use Tester\Environment;
Expand Down Expand Up @@ -238,6 +239,51 @@ class RelationshipOneHasManyTest extends DataTestCase
sort($ids);
Assert::same([1, 2], $ids);
}


public function testCountAfterRemoveAndFlushAndCount()
{
$author = new Author();
$author->name = 'The Imp';
$author->web = 'localhost';
$author->born = '2000-01-01 12:12:12';

$this->orm->authors->attach($author);

$publisher = new Publisher();
$publisher->name = 'Valyria';

$book = new Book();
$book->author = $author;
$book->title = 'The Wall';
$book->publisher = $publisher;
$book->translator = $author;

$this->orm->authors->persistAndFlush($author);

Assert::same(1, \count($author->books));

foreach ($author->books as $book) {
$this->orm->books->remove($book);
}

Assert::same(0, \count($author->books));

$this->orm->books->flush();

Assert::same(0, \count($author->books));

$book3 = new Book();
$book3->author = $author;
$book3->title = 'The Wall III';
$book3->publisher = $publisher;

Assert::same(1, \count($author->books));

$this->orm->books->persist($book3);

Assert::same(1, \count($author->books));
}
}


Expand Down

0 comments on commit 8f98094

Please sign in to comment.