diff --git a/system/Model.php b/system/Model.php index e66f12092469..4b39bf6aec8a 100644 --- a/system/Model.php +++ b/system/Model.php @@ -798,6 +798,20 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur && ! empty($data->{$this->primaryKey}) ) ) { + // For Entity + if (method_exists($data, 'cast')) { + // Disable Entity cast, because raw data is needed for database. + $cast = $data->cast(); + $data->cast(false); + + $properties[$this->primaryKey] = $data->{$this->primaryKey}; + + // Restore Entity cast setting. + $data->cast($cast); + + return $properties; + } + $properties[$this->primaryKey] = $data->{$this->primaryKey}; }