Skip to content

Commit c20bef3

Browse files
committed
Merge pull request #55 from redwormik/table-ref-null
Selection::getReferencedTable always reloads when $row[$column] is NULL
2 parents debd0f2 + 0cc6526 commit c20bef3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Database/Table/Selection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ public function getReferencedTable(ActiveRow $row, $table, $column = NULL)
846846
$referenced = & $this->refCache['referenced'][$this->getSpecificCacheKey()]["$table.$column"];
847847
$selection = & $referenced['selection'];
848848
$cacheKeys = & $referenced['cacheKeys'];
849-
if ($selection === NULL || !isset($cacheKeys[$checkPrimaryKey])) {
849+
if ($selection === NULL || ($checkPrimaryKey !== NULL && !isset($cacheKeys[$checkPrimaryKey]))) {
850850
$this->execute();
851851
$cacheKeys = array();
852852
foreach ($this->rows as $row) {

tests/Database/Table/Table.ref().phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,20 @@ test(function() use ($context) {
3131
test(function() use ($context) {
3232
Assert::null($context->table('book')->get(2)->ref('author', 'translator_id'));
3333
});
34+
35+
test(function() use ($context, $connection) {
36+
$counter = 0;
37+
38+
$connection->onQuery[] = function($connection, $result) use (&$counter) {
39+
$counter++;
40+
};
41+
42+
$table = $context->table('book');
43+
44+
$names = array();
45+
foreach ($table as $book) {
46+
$translator = $book->ref('author', 'translator_id');
47+
}
48+
49+
Assert::equal(2, $counter);
50+
});

0 commit comments

Comments
 (0)