Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit c509f40

Browse files
author
Nik Barham
committed
New "Cache Clearing" code wasn't clearing enough properties!
Updated Dump output to bypass local property cache
1 parent 8b10979 commit c509f40

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/Automatorm/Orm/Dump.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function _dump(Model $model)
4444
if (substr($method, 0, 10) == '_property_')
4545
{
4646
$key = substr($method, 10);
47-
$value = $this->$key;
47+
$value = $this->$method();
4848
$output .= " " . \Automatorm\Orm\Dump::format($key, $value, $seen);
4949
$seen[$key] = true;
5050
}
@@ -61,7 +61,7 @@ public function _dump(Model $model)
6161
$output .= " <span><strong>1-1</strong></span> =>\n";
6262
if ($schema['one-to-one']) foreach ($schema['one-to-one'] as $key => $contents)
6363
{
64-
$value = $this->$key;
64+
$value = $this->_data->$key;
6565

6666
$output .= " " . \Automatorm\Orm\Dump::format($key, $value, $seen);
6767
$seen[$key] = true;
@@ -70,7 +70,7 @@ public function _dump(Model $model)
7070
$output .= " <span><strong>*-1</strong></span> =>\n";
7171
if ($schema['many-to-one']) foreach ($schema['many-to-one'] as $key => $contents)
7272
{
73-
$value = $this->$key;
73+
$value = $this->_data->$key;
7474

7575
$output .= " " . \Automatorm\Orm\Dump::format($key, $value, $seen);
7676
$seen[$key] = true;
@@ -79,7 +79,7 @@ public function _dump(Model $model)
7979
$output .= " <span><strong>1-*</strong></span> =>\n";
8080
if ($schema['one-to-many']) foreach ($schema['one-to-many'] as $key => $contents)
8181
{
82-
$value = $this->$key;
82+
$value = $this->_data->$key;
8383

8484
$output .= " " . \Automatorm\Orm\Dump::format($key, $value, $seen);
8585
$seen[$key] = true;
@@ -88,7 +88,7 @@ public function _dump(Model $model)
8888
$output .= " <span><strong>*-*</strong></span> =>\n";
8989
if ($schema['many-to-many']) foreach ($schema['many-to-many'] as $key => $contents)
9090
{
91-
$value = $this->$key;
91+
$value = $this->_data->$key;
9292

9393
$output .= " " . \Automatorm\Orm\Dump::format($key, $value, $seen);
9494
$seen[$key] = true;

src/Automatorm/Orm/Model.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,43 @@ final public function dataUpdate(Data $db)
369369
final public function dataClearCache()
370370
{
371371
$modelschema = $this->_data->getModel();
372+
373+
// Clean out cached column data
372374
foreach ($modelschema['columns'] as $column => $type)
373375
{
374376
if ($column != 'id') unset($this->{$column});
375377
}
378+
379+
// Clean out cached "dynamic property" data
380+
foreach (get_class_methods(get_called_class()) as $methodname)
381+
{
382+
if (substr($methodname,0,10) == '_property_')
383+
{
384+
$column = substr($methodname,10);
385+
unset($this->{$column});
386+
}
387+
}
388+
389+
// Clean out cached external data
390+
foreach ($modelschema['one-to-one'] as $column => $value)
391+
{
392+
if ($column != 'id') unset($this->{$column});
393+
}
394+
395+
foreach ($modelschema['one-to-many'] as $column => $value)
396+
{
397+
if ($column != 'id') unset($this->{$column});
398+
}
399+
400+
foreach ($modelschema['many-to-many'] as $column => $value)
401+
{
402+
if ($column != 'id') unset($this->{$column});
403+
}
404+
405+
foreach ($modelschema['many-to-one'] as $column => $value)
406+
{
407+
if ($column != 'id') unset($this->{$column});
408+
}
376409
}
377410

378411
// Grab a clean version of the Data object based on the current state in the database.

0 commit comments

Comments
 (0)