Skip to content

Commit 21145df

Browse files
committed
Selection: Related prototype depends on specific cache key
1 parent 3c7309a commit 21145df

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Database/Table/Selection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public function getReferencingTable($table, $column, $active = NULL)
893893
list($table, $column) = $hasMany;
894894
}
895895

896-
$prototype = & $this->refCache['referencingPrototype']["$table.$column"];
896+
$prototype = & $this->refCache['referencingPrototype'][$this->getSpecificCacheKey()]["$table.$column"];
897897
if (!$prototype) {
898898
$prototype = $this->createGroupedSelectionInstance($table, $column);
899899
$prototype->where("$table.$column", array_keys((array) $this->rows));

tests/Database/Table/Table.related().caching.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,22 @@ test(function() use ($context) {
7878
'Jakub Vrana',
7979
), $translators);
8080
});
81+
82+
83+
84+
test(function() use ($context) { // cache can't be affected by inner query!
85+
$author = $context->table('author')->get(11);
86+
$secondBookTagRels = NULL;
87+
foreach ($author->related('book')->order('id') as $book) {
88+
if (!isset($secondBookTagRels)) {
89+
$bookFromAnotherSelection = $author->related('book')->where('id', $book->id)->fetch();
90+
$bookFromAnotherSelection->related('book_tag')->fetchPairs('id');
91+
$secondBookTagRels = array();
92+
} else {
93+
foreach ($book->related('book_tag') as $bookTagRel) {
94+
$secondBookTagRels[] = $bookTagRel->tag->name;
95+
}
96+
}
97+
}
98+
Assert::same(array('JavaScript'), $secondBookTagRels);
99+
});

0 commit comments

Comments
 (0)