Skip to content

Commit

Permalink
fix: Entity's primary key is cast when inserting
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Aug 10, 2023
1 parent ae64b36 commit e32feba
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

Expand Down

0 comments on commit e32feba

Please sign in to comment.