diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 07eb403f0..ae19e51ef 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -815,13 +815,18 @@ class Model extends Overloadable { * @access public */ function deconstruct($field, $data) { + if (!is_array($data)) { + return $data; + } + $copy = $data; $type = $this->getColumnType($field); - $db =& ConnectionManager::getDataSource($this->useDbConfig); if (in_array($type, array('datetime', 'timestamp', 'date', 'time'))) { $useNewDate = (isset($data['year']) || isset($data['month']) || isset($data['day']) || isset($data['hour']) || isset($data['minute'])); $dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec'); + + $db =& ConnectionManager::getDataSource($this->useDbConfig); $format = $db->columns[$type]['format']; $date = array(); @@ -1380,7 +1385,7 @@ class Model extends Overloadable { if ($keys['old'][$foreignKey] != $keys[$foreignKey]) { $conditions[$fkQuoted] = $keys['old'][$foreignKey]; $count = intval($this->find('count', compact('conditions', 'recursive'))); - + $this->{$parent}->updateAll( array($assoc['counterCache'] => $count), array($this->{$parent}->escapeField() => $keys['old'][$foreignKey]) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index cdf931310..7ac8b0dd3 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -102,7 +102,7 @@ class ModelTest extends CakeTestCase { /** * Tests getAssociated method - * + * * @access public * @return void */ @@ -4051,10 +4051,10 @@ class ModelTest extends CakeTestCase { $TestModel2->saveField('published', true); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '2'); - + $TestModel2->save(array('id' => 1, 'syfile_id' => 1, 'published'=> false)); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); + $this->assertIdentical($result['Syfile']['item_count'], '1'); } /** * testDel method @@ -5906,6 +5906,19 @@ class ModelTest extends CakeTestCase { $TestModel->set($data); $expected = array('Apple'=> array('mytime'=> '03:04:04')); $this->assertEqual($TestModel->data, $expected); + + $db = ConnectionManager::getDataSource('test_suite'); + $data = array(); + $data['Apple']['modified'] = $db->expression('NOW()'); + $TestModel->data = null; + $TestModel->set($data); + $this->assertEqual($TestModel->data, $data); + + $data = array(); + $data['Apple']['mytime'] = $db->expression('NOW()'); + $TestModel->data = null; + $TestModel->set($data); + $this->assertEqual($TestModel->data, $data); } /** * testTablePrefixSwitching method