优化getChangedData判断

修复多态关联无法保存的问题
This commit is contained in:
Karson
2024-03-26 17:19:19 +08:00
parent 988c95b7ba
commit 1a609a99c6
2 changed files with 10 additions and 2 deletions

View File

@@ -1267,10 +1267,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$data = $this->data;
} else {
$data = array_udiff_assoc($this->data, $this->origin, function ($a, $b) {
if (is_numeric($a) && is_numeric($b)) {
if (strcmp($a, $b) !== 0) {
return 1;
}
if ($a == $b) {
return 0;
}
}
if ((empty($a) || empty($b)) && $a !== $b) {
return 1;
}
return is_object($a) || $a != $b ? 1 : 0;
return is_object($a) || $a !== $b ? 1 : 0;
});
}

View File

@@ -211,7 +211,7 @@ class MorphOne extends Relation
$model = new $this->model();
return $model->save() ? $model : false;
return $model->save($data) ? $model : false;
}
/**