From a92681af45b664bd5f29f1116c78954ced20f0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=9Alawski?= Date: Thu, 23 Mar 2017 15:23:40 +0100 Subject: [PATCH] Fixed _doLowUpdate warning --- CHANGELOG.md | 1 + phalcon/mvc/model.zep | 6 +++++- tests/unit/Mvc/Model/SnapshotTest.php | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 337973b0603..ac31ef7eed9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # [3.1.1](https://github.com/phalcon/cphalcon/releases/tag/v3.1.1) (2017-XX-XX) - Fixed undefined index warning on existing cached resultsets +- Fixed `Phalcon\Mvc\Model::_dowLowUpdate` warning first argument is not an array # [3.1.0](https://github.com/phalcon/cphalcon/releases/tag/v3.1.0) (2017-03-22) - Added `Phalcon\Validation\Validator\Callback`, `Phalcon\Validation::getData` diff --git a/phalcon/mvc/model.zep b/phalcon/mvc/model.zep index 9ef68e760a5..de7b31ec3ce 100644 --- a/phalcon/mvc/model.zep +++ b/phalcon/mvc/model.zep @@ -2650,7 +2650,11 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface ], bindTypes); if success && manager->isKeepingSnapshots(this) { - let this->_snapshot = array_merge(this->_snapshot, newSnapshot); + if typeof this->_snapshot == "array" { + let this->_snapshot = array_merge(this->_snapshot, newSnapshot); + } else { + let this->_snapshot = newSnapshot; + } } return success; diff --git a/tests/unit/Mvc/Model/SnapshotTest.php b/tests/unit/Mvc/Model/SnapshotTest.php index 5e0f6ed0652..ff8ebb3fb58 100644 --- a/tests/unit/Mvc/Model/SnapshotTest.php +++ b/tests/unit/Mvc/Model/SnapshotTest.php @@ -299,4 +299,21 @@ function () { } ); } + + /** + * @author Wojciech Ĺšlawski + * @since 2017-03-23 + */ + public function testNewInstanceUpdate() + { + $this->specify( + 'When updating model from new instance there is some problem', + function () { + $this->setUpModelsManager(); + $robots = Robots::findFirst(); + $robots = new Robots($robots->toArray()); + expect($robots->save())->true(); + } + ); + } }