From 0d4563826a4bbe48e2d6f24fc426e205f6925ff4 Mon Sep 17 00:00:00 2001 From: Egor Vasyakin Date: Wed, 18 Aug 2021 15:30:43 +0300 Subject: [PATCH] Update ActiveRecord.php --- src/ActiveRecord.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 065c06c..de75860 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -172,6 +172,21 @@ public function getRowProperties(): array return $props; } + /** + * Получение состояния сохраняемых полей. + * @return array + */ + public function getState(): array + { + $state = static::getDb()->identityMapGetState($this, static::primaryKey()); + foreach ($state as $name => &$value) { + if (!in_array($name, static::columns())) { + unset($state[$name]); + } + } + return $state; + } + /** * Получение маппинга измененных свойств записи. * @return array @@ -183,7 +198,8 @@ public function getUpdatedProperties(): array if (empty($this->$pk)) { return $props; } else { - $state = static::getDb()->identityMapGetState($this, $pk); + // $state = static::getDb()->identityMapGetState($this, $pk); + $state = $this->getState(); // return array_diff($props, $state ?? []); return array_merge( array_fill_keys(array_keys(array_diff($state ?? [], $props)), null),