From 1a609a99c66e99f387fc517189fc702fe1d7c00c Mon Sep 17 00:00:00 2001 From: Karson Date: Tue, 26 Mar 2024 17:19:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96getChangedData=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复多态关联无法保存的问题 --- library/think/Model.php | 10 +++++++++- library/think/model/relation/MorphOne.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index fcae0ae9..617ea74d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -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; }); } diff --git a/library/think/model/relation/MorphOne.php b/library/think/model/relation/MorphOne.php index 5ec71724..d7f17129 100644 --- a/library/think/model/relation/MorphOne.php +++ b/library/think/model/relation/MorphOne.php @@ -211,7 +211,7 @@ class MorphOne extends Relation $model = new $this->model(); - return $model->save() ? $model : false; + return $model->save($data) ? $model : false; } /**