Skip to content

Commit 1af77e1

Browse files
committed
Merge pull request #66 from matej21/fix/active_row_infinite_recursion
Table: fixed infinite recursion
2 parents 531dd88 + e717a69 commit 1af77e1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/Database/Table/ActiveRow.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,17 @@ public function __unset($key)
313313
}
314314

315315

316-
protected function accessColumn($key, $selectColumn = TRUE)
316+
/**
317+
* @internal
318+
*/
319+
public function accessColumn($key, $selectColumn = TRUE)
317320
{
318321
$this->table->accessColumn($key, $selectColumn);
319322
if ($this->table->getDataRefreshed() && !$this->dataRefreshed) {
320323
$this->data = $this->table[$this->getSignature()]->data;
321324
$this->dataRefreshed = TRUE;
322325
}
326+
return array_key_exists($key, $this->data);
323327
}
324328

325329

src/Database/Table/Selection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ public function getReferencedTable(ActiveRow $row, $table, $column = NULL)
840840
}
841841
list($table, $column) = $belongsTo;
842842
}
843+
if (!$row->accessColumn($column)) {
844+
return FALSE;
845+
}
843846

844847
$checkPrimaryKey = $row[$column];
845848

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Database\Table & StaticConventions: bug causing infinite recursion
5+
* @dataProvider? ../../databases.ini
6+
*/
7+
8+
use Tester\Assert;
9+
10+
require __DIR__ . '/../../connect.inc.php'; // create $connection
11+
12+
$conventions = new \Nette\Database\Conventions\StaticConventions();
13+
$cacheStorage = new \Nette\Caching\Storages\MemoryStorage();
14+
$context = new \Nette\Database\Context($context->getConnection(), $context->getStructure(), $conventions, $cacheStorage);
15+
16+
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql");
17+
18+
19+
test(function() use ($context) {
20+
$book = $context->table('book')->where('id = ?', 1)->fetch();
21+
Assert::exception(function () use ($book) {
22+
$book->unknown_column;
23+
}, 'Nette\MemberAccessException', "Cannot read an undeclared column 'unknown_column'.");
24+
});

0 commit comments

Comments
 (0)