From b3a6a06f805bae4f0e88cb8662ebd3b7d58f6dbc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 26 Oct 2008 15:02:01 +0000 Subject: [PATCH] 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 --- cake/libs/model/model.php | 3 +++ cake/tests/cases/libs/model/model.test.php | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index b63611aaf..529c8b17c 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -813,6 +813,9 @@ class Model extends Overloadable { } } $date = str_replace(array_keys($date), array_values($date), $format); + if ($type == 'time' && $date == '00:00:00') { + return null; + } if ($useNewDate && (!empty($date))) { return $date; diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 430805c23..4bd9dbbb2 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -5136,6 +5136,7 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('Apple'); $TestModel =& new Apple(); + //test null/empty values first $data['Apple']['created']['year'] = ''; $data['Apple']['created']['month'] = ''; $data['Apple']['created']['day'] = ''; @@ -5148,6 +5149,27 @@ class ModelTest extends CakeTestCase { $expected = array('Apple'=> array('created'=> '')); $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['Apple']['created']['year'] = '2007'; $data['Apple']['created']['month'] = '08';