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
This commit is contained in:
jperras 2009-06-02 03:23:15 +00:00
parent a9bbae31ee
commit d2b4995e43
2 changed files with 23 additions and 5 deletions

View file

@ -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();

View file

@ -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