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/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/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', + ] + ); + } + ); + } }