Applying patch from 'BrendonCoz'. Model::deconstruct() now allows null for time column types. Closes #5659

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7782 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-10-26 15:02:01 +00:00
parent 2d1483e1e5
commit b3a6a06f80
2 changed files with 25 additions and 0 deletions

View file

@ -813,6 +813,9 @@ class Model extends Overloadable {
} }
} }
$date = str_replace(array_keys($date), array_values($date), $format); $date = str_replace(array_keys($date), array_values($date), $format);
if ($type == 'time' && $date == '00:00:00') {
return null;
}
if ($useNewDate && (!empty($date))) { if ($useNewDate && (!empty($date))) {
return $date; return $date;

View file

@ -5136,6 +5136,7 @@ class ModelTest extends CakeTestCase {
$this->loadFixtures('Apple'); $this->loadFixtures('Apple');
$TestModel =& new Apple(); $TestModel =& new Apple();
//test null/empty values first
$data['Apple']['created']['year'] = ''; $data['Apple']['created']['year'] = '';
$data['Apple']['created']['month'] = ''; $data['Apple']['created']['month'] = '';
$data['Apple']['created']['day'] = ''; $data['Apple']['created']['day'] = '';
@ -5148,6 +5149,27 @@ class ModelTest extends CakeTestCase {
$expected = array('Apple'=> array('created'=> '')); $expected = array('Apple'=> array('created'=> ''));
$this->assertEqual($TestModel->data, $expected); $this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['date']['year'] = '';
$data['Apple']['date']['month'] = '';
$data['Apple']['date']['day'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('date'=> ''));
$this->assertEqual($TestModel->data, $expected);
$data = array();
$data['Apple']['mytime']['hour'] = '';
$data['Apple']['mytime']['min'] = '';
$data['Apple']['mytime']['sec'] = '';
$TestModel->data = null;
$TestModel->set($data);
$expected = array('Apple'=> array('mytime'=> ''));
$this->assertEqual($TestModel->data, $expected);
//test other data variations
$data = array(); $data = array();
$data['Apple']['created']['year'] = '2007'; $data['Apple']['created']['year'] = '2007';
$data['Apple']['created']['month'] = '08'; $data['Apple']['created']['month'] = '08';