From 8e40926b72c1239c18b3fe94fbccca44433f4510 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 | 8 ++++++-- tests/unit/Mvc/Model/SnapshotTest.php | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 337973b0603..b856fd78663 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 [#12742](https://github.com/phalcon/cphalcon/issues/12742) # [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..f7bcde283dc 100644 --- a/phalcon/mvc/model.zep +++ b/phalcon/mvc/model.zep @@ -2650,8 +2650,12 @@ 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(); + } + ); + } }