Skip to content

Commit

Permalink
relationships: derived collection is not cached & stored in collectio…
Browse files Browse the repository at this point in the history
…n itself
  • Loading branch information
hrach committed Jan 28, 2017
1 parent 32aae90 commit 3d26439
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Relationships/HasMany.php
Expand Up @@ -294,7 +294,10 @@ protected function getCollection($forceNew = false)
$collection = $this->applyDefaultOrder($collection);
}

return $this->collection = $collection;
if (!$forceNew) {
$this->collection = $collection;
}
return $collection;
}


Expand Down
Expand Up @@ -289,6 +289,24 @@ class RelationshipsOneHasManyCollectionTest extends DataTestCase
}


public function testFetchDerivedCollection()
{
$queries = $this->getQueries(function () {
Assert::count(0, $this->books->getEntitiesForPersistence());

$this->books->add($this->createBook());
Assert::count(1, $this->books->getEntitiesForPersistence());

$this->books->get()->fetchAll();
Assert::count(1, $this->books->getEntitiesForPersistence());
});

if ($queries) {
Assert::count(1, $queries); // SELECT NONSENCE
}
}


public function testRemoveA()
{
$queries = $this->getQueries(function () {
Expand Down

0 comments on commit 3d26439

Please sign in to comment.