Skip to content

Commit

Permalink
Update ActiveRecord.php
Browse files Browse the repository at this point in the history
  • Loading branch information
evasyakin committed Aug 18, 2021
1 parent 0b6efc3 commit 0d45638
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit 0d45638

Please sign in to comment.