From ae79d50053efd5ac439a308c8d9407350d3dc092 Mon Sep 17 00:00:00 2001 From: Simon Karlen Date: Mon, 16 Oct 2017 18:06:02 +0200 Subject: [PATCH] set old attributes on init if pk's are set --- ActiveRecord.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ActiveRecord.php b/ActiveRecord.php index 0a286cc..10f1edf 100644 --- a/ActiveRecord.php +++ b/ActiveRecord.php @@ -37,6 +37,14 @@ class ActiveRecord extends BaseActiveRecord { */ public function __construct(array $attributes = [], $config = []) { $this->_isConstructing = true; + $setOld = true; + $keys = $this->primaryKey(); + foreach ($keys as $key) { + if (!isset($attributes[$key])) { + $setOld = false; + break; + } + } foreach ($attributes as $name => $value) { if (is_int($name)) { $this->setAttribute($value, null); @@ -44,6 +52,9 @@ public function __construct(array $attributes = [], $config = []) { $this->setAttribute($name, $value); } } + if ($setOld) { + $this->setOldAttributes($attributes); + } $this->_isConstructing = false; parent::__construct($config); }