Skip to content

Commit 0b6efc3

Browse files
committed
Update ActiveRecord.php
1 parent e6310db commit 0b6efc3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/ActiveRecord.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ public function getUpdatedProperties(): array
184184
return $props;
185185
} else {
186186
$state = static::getDb()->identityMapGetState($this, $pk);
187-
return array_diff($props, $state ?? []);
187+
// return array_diff($props, $state ?? []);
188+
return array_merge(
189+
array_fill_keys(array_keys(array_diff($state ?? [], $props)), null),
190+
array_diff($props, $state ?? [])
191+
);
188192
}
189193
}
190194

@@ -196,8 +200,7 @@ public function getUpdatedProperties(): array
196200
*/
197201
public function save()
198202
{
199-
$props = $this->getUpdatedProperties();
200-
if (empty($props)) {
203+
if (empty($this->getUpdatedProperties())) {
201204
$this->hook('nothingSave');
202205
return $this;
203206
}
@@ -206,15 +209,15 @@ public function save()
206209
$pk = static::primaryKey();
207210
if (empty($this->$pk)) {
208211
$this->hook('beforeInsert');
209-
static::getDb(true)->insert(static::tableName(), $props);
212+
static::getDb(true)->insert(static::tableName(), $this->getUpdatedProperties());
210213
$this->$pk = static::lastInsertId();
211214
if (empty($this->$pk)) {
212215
throw new LastInsertIdUndefinedException();
213216
}
214217
$this->hook('afterInsert');
215218
} else {
216219
$this->hook('beforeUpdate');
217-
static::getDb(true)->update(static::tableName(), $props)
220+
static::getDb(true)->update(static::tableName(), $this->getUpdatedProperties())
218221
->where("$pk = ?", [$this->$pk])->one();
219222
$this->hook('afterUpdate');
220223
}

0 commit comments

Comments
 (0)