From 09b5ed4ba1168505da658af82d401b48275762b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=9Alawski?= Date: Thu, 9 Mar 2017 12:07:55 +0100 Subject: [PATCH] Fixes #12688 --- CHANGELOG.md | 3 ++- config.json | 1 + phalcon/mvc/model.zep | 2 +- tests/_data/models/Statistics/AgeStats.php | 2 +- tests/_data/models/Statistics/CityStats.php | 2 +- tests/_data/models/Statistics/GenderStats.php | 2 +- tests/_data/resultsets/Stats.php | 2 +- tests/unit/Mvc/ModelTest.php | 25 +++++++++++++++++++ 8 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2409dc7e77e..7c558b5f975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ - Fixed `Phalcon\Mvc\Model::getChangedFields` to correct detect changes from NULL to Zero [#12628](https://github.com/phalcon/cphalcon/issues/12628) - Fixed `Phalcon\Mvc\Model` to create/refresh snapshot after create/update/refresh operation [#11007](https://github.com/phalcon/cphalcon/issues/11007), [#11818](https://github.com/phalcon/cphalcon/issues/11818), [#11424](https://github.com/phalcon/cphalcon/issues/11424) - Fixed `Phalcon\Mvc\Model::validate` to correctly set code message [#12645](https://github.com/phalcon/cphalcon/issues/12645) -- Added the value of the object intanceof Interface to `Phalcon\AcMl\Adapter\Memory` +- Added the value of the object intanceof Interface to `Phalcon\Acl\Adapter\Memory` +- Fixed `Phalcon\Mvc\Model` to correctly add error when try to save empty string value to not null and not default column [#12688](https://github.com/phalcon/cphalcon/issues/12688) # [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (2017-02-20) - Fixed Isnull check is not correct when the model field defaults to an empty string. [#12507](https://github.com/phalcon/cphalcon/issues/12507) diff --git a/config.json b/config.json index 4cf954258fb..f036174dd4a 100644 --- a/config.json +++ b/config.json @@ -6,6 +6,7 @@ "constant-folding": true, "static-constant-class-folding": true }, + "namespace": "phalcon", "name": "phalcon", "description": "Web framework delivered as a C-extension for PHP", diff --git a/phalcon/mvc/model.zep b/phalcon/mvc/model.zep index b3e00d0ee8d..9ef68e760a5 100644 --- a/phalcon/mvc/model.zep +++ b/phalcon/mvc/model.zep @@ -2091,7 +2091,7 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface let isNull = true; } } else { - if value === null || (value === "" && value !== defaultValues[field]) { + if value === null || (value === "" && (!isset defaultValues[field] || value !== defaultValues[field])) { let isNull = true; } } diff --git a/tests/_data/models/Statistics/AgeStats.php b/tests/_data/models/Statistics/AgeStats.php index 1050a0ad733..e4e657b073e 100644 --- a/tests/_data/models/Statistics/AgeStats.php +++ b/tests/_data/models/Statistics/AgeStats.php @@ -7,7 +7,7 @@ /** * \Phalcon\Test\Models\Statistics\AgeStats * - * @copyright (c) 2011-2016 Phalcon Team + * @copyright (c) 2011-2017 Phalcon Team * @link http://www.phalconphp.com * @author Eugene Smirnov * @package Phalcon\Test\Models\Statistics diff --git a/tests/_data/models/Statistics/CityStats.php b/tests/_data/models/Statistics/CityStats.php index 59bfd8d964b..158a235785f 100644 --- a/tests/_data/models/Statistics/CityStats.php +++ b/tests/_data/models/Statistics/CityStats.php @@ -7,7 +7,7 @@ /** * \Phalcon\Test\Models\Statistics\CityStats * - * @copyright (c) 2011-2016 Phalcon Team + * @copyright (c) 2011-2017 Phalcon Team * @link http://www.phalconphp.com * @author Eugene Smirnov * @package Phalcon\Test\Models\Statistics diff --git a/tests/_data/models/Statistics/GenderStats.php b/tests/_data/models/Statistics/GenderStats.php index 4951bdddd03..5e3d059a067 100644 --- a/tests/_data/models/Statistics/GenderStats.php +++ b/tests/_data/models/Statistics/GenderStats.php @@ -7,7 +7,7 @@ /** * \Phalcon\Test\Models\Statistics\GenderStats * - * @copyright (c) 2011-2016 Phalcon Team + * @copyright (c) 2011-2017 Phalcon Team * @link http://www.phalconphp.com * @author Eugene Smirnov * @package Phalcon\Test\Models\Statistics diff --git a/tests/_data/resultsets/Stats.php b/tests/_data/resultsets/Stats.php index 99698ee6f23..9a6d8bf5f67 100644 --- a/tests/_data/resultsets/Stats.php +++ b/tests/_data/resultsets/Stats.php @@ -7,7 +7,7 @@ /** * \Phalcon\Test\Resultsets\Stats * - * @copyright (c) 2011-2016 Phalcon Team + * @copyright (c) 2011-2017 Phalcon Team * @link http://www.phalconphp.com * @author Eugene Smirnov * @package Phalcon\Test\Resultsets diff --git a/tests/unit/Mvc/ModelTest.php b/tests/unit/Mvc/ModelTest.php index ecf2be6fc8e..f9ea544968e 100644 --- a/tests/unit/Mvc/ModelTest.php +++ b/tests/unit/Mvc/ModelTest.php @@ -2,6 +2,7 @@ namespace Phalcon\Test\Unit\Mvc; +use DateTime; use Helper\ModelTrait; use Phalcon\Mvc\Model\Message; use Phalcon\Test\Models\Users; @@ -646,4 +647,28 @@ function () { } ); } + + /** + * Tests empty string value on not null + * + * @issue 12688 + * @author Wojciech Ĺšlawski + * @since 2017-03-09 + */ + public function testIssue12688() + { + $this->specify( + 'Issue 12688 is happening', + function () { + $robots = new Robots(); + $robots->name = ''; + $robots->save( + [ + 'datetime' => (new DateTime())->format('Y-m-d'), + 'text' => 'text', + ] + ); + } + ); + } }