Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating Model::deconstruct to handle db expressions correctly. Fixes…

… #6372; thanks to mattcurry for the patch.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8185 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit d2b4995e439430caab2613b13fe006ba36cf25c9 1 parent a9bbae3
Joel Perras jperras authored
9 cake/libs/model/model.php
View
@@ -815,13 +815,18 @@ function set($one, $two = null) {
* @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 @@ function updateCounterCache($keys = array(), $created = false) {
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])
19 cake/tests/cases/libs/model/model.test.php
View
@@ -102,7 +102,7 @@ function endTest() {
/**
* Tests getAssociated method
- *
+ *
* @access public
* @return void
*/
@@ -4051,10 +4051,10 @@ function testSaveWithCounterCacheScope() {
$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 @@ function testDeconstructFields() {
$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
Please sign in to comment.
Something went wrong with that request. Please try again.