Skip to content

Commit a967f50

Browse files
committed
refactor!: use toDatabase() in BaseModel
1 parent c6c60bd commit a967f50

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

system/BaseModel.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Database\Exceptions\DatabaseException;
1818
use CodeIgniter\Database\Exceptions\DataException;
1919
use CodeIgniter\Database\Query;
20+
use CodeIgniter\Entity\Entity;
2021
use CodeIgniter\Exceptions\ModelException;
2122
use CodeIgniter\I18n\Time;
2223
use CodeIgniter\Pager\Pager;
@@ -1684,8 +1685,11 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv
16841685
*/
16851686
protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): array
16861687
{
1688+
if ($data instanceof Entity) {
1689+
$properties = $data->toDatabase($onlyChanged, $recursive);
1690+
}
16871691
// @TODO Should define Interface or Class. Entity has toRawArray() now.
1688-
if (method_exists($data, 'toRawArray')) {
1692+
elseif (method_exists($data, 'toRawArray')) {
16891693
$properties = $data->toRawArray($onlyChanged, $recursive);
16901694
} else {
16911695
$mirror = new ReflectionClass($data);
@@ -1706,7 +1710,7 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
17061710
}
17071711

17081712
/**
1709-
* Transform data to array.
1713+
* Transform data to array that can be save to database.
17101714
*
17111715
* @param array|object|null $data Data
17121716
* @param string $type Type of data (insert|update)

0 commit comments

Comments
 (0)