Skip to content

Commit

Permalink
relationship: fixed ManyHasMany::set() method which may work with wro…
Browse files Browse the repository at this point in the history
…ng data
  • Loading branch information
hrach committed Mar 30, 2017
1 parent 2da1cf5 commit 4f8d790
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Relationships/HasMany.php
Expand Up @@ -303,6 +303,7 @@ protected function getCachedCollection()
$cache->$key = $this->createCollection();
}
$this->collection = $cache->$key;
$this->collection = $this->collection->setRelationshipParent($this->parent);
return $cache->$key;
}

Expand Down
Expand Up @@ -145,6 +145,23 @@ class RelationshipManyHasManyTest extends DataTestCase
}


public function testCachingPreload()
{
// init caches
$books = $this->orm->books->findAll();
foreach ($books as $book) {
iterator_to_array($book->tags);
}

$book = $this->orm->books->getById(2);

Assert::false($book->tags->has(1));
Assert::true($book->tags->has(2));
Assert::true($book->tags->has(3));
Assert::false($book->tags->has(4));
}


public function testIsModified()
{
$tag = new Tag('A');
Expand Down

0 comments on commit 4f8d790

Please sign in to comment.