Skip to content

Commit e32feba

Browse files
committed
fix: Entity's primary key is cast when inserting
1 parent ae64b36 commit e32feba

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

system/Model.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,20 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
798798
&& ! empty($data->{$this->primaryKey})
799799
)
800800
) {
801+
// For Entity
802+
if (method_exists($data, 'cast')) {
803+
// Disable Entity cast, because raw data is needed for database.
804+
$cast = $data->cast();
805+
$data->cast(false);
806+
807+
$properties[$this->primaryKey] = $data->{$this->primaryKey};
808+
809+
// Restore Entity cast setting.
810+
$data->cast($cast);
811+
812+
return $properties;
813+
}
814+
801815
$properties[$this->primaryKey] = $data->{$this->primaryKey};
802816
}
803817

0 commit comments

Comments
 (0)