Skip to content

Commit 366bcbe

Browse files
committed
fix: use instanceof Entity
`method_exists($data, 'cast')` is too loose, and not good.
1 parent d5a85e3 commit 366bcbe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

system/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use CodeIgniter\Database\Exceptions\DatabaseException;
2121
use CodeIgniter\Database\Exceptions\DataException;
2222
use CodeIgniter\Database\Query;
23+
use CodeIgniter\Entity\Entity;
2324
use CodeIgniter\Exceptions\ModelException;
2425
use CodeIgniter\I18n\Time;
2526
use CodeIgniter\Validation\ValidationInterface;
@@ -790,8 +791,7 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
790791

791792
$primaryKey = null;
792793

793-
// For Entity
794-
if (method_exists($data, 'cast')) {
794+
if ($data instanceof Entity) {
795795
$cast = $data->cast();
796796

797797
// Disable Entity casting, because raw primary key data is needed for database.

0 commit comments

Comments
 (0)