From 21145df7cbab74fda6b05a760b92205c6e9d0d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20H=C3=A1k?= Date: Thu, 30 Apr 2015 00:57:36 +0200 Subject: [PATCH] Selection: Related prototype depends on specific cache key --- src/Database/Table/Selection.php | 2 +- .../Table/Table.related().caching.phpt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 65809a1ab..154372d70 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -893,7 +893,7 @@ public function getReferencingTable($table, $column, $active = NULL) list($table, $column) = $hasMany; } - $prototype = & $this->refCache['referencingPrototype']["$table.$column"]; + $prototype = & $this->refCache['referencingPrototype'][$this->getSpecificCacheKey()]["$table.$column"]; if (!$prototype) { $prototype = $this->createGroupedSelectionInstance($table, $column); $prototype->where("$table.$column", array_keys((array) $this->rows)); diff --git a/tests/Database/Table/Table.related().caching.phpt b/tests/Database/Table/Table.related().caching.phpt index 2c92c3acd..4325a8eb3 100644 --- a/tests/Database/Table/Table.related().caching.phpt +++ b/tests/Database/Table/Table.related().caching.phpt @@ -78,3 +78,22 @@ test(function() use ($context) { 'Jakub Vrana', ), $translators); }); + + + +test(function() use ($context) { // cache can't be affected by inner query! + $author = $context->table('author')->get(11); + $secondBookTagRels = NULL; + foreach ($author->related('book')->order('id') as $book) { + if (!isset($secondBookTagRels)) { + $bookFromAnotherSelection = $author->related('book')->where('id', $book->id)->fetch(); + $bookFromAnotherSelection->related('book_tag')->fetchPairs('id'); + $secondBookTagRels = array(); + } else { + foreach ($book->related('book_tag') as $bookTagRel) { + $secondBookTagRels[] = $bookTagRel->tag->name; + } + } + } + Assert::same(array('JavaScript'), $secondBookTagRels); +});