17
17
use CodeIgniter \Database \Exceptions \DatabaseException ;
18
18
use CodeIgniter \Database \Exceptions \DataException ;
19
19
use CodeIgniter \Database \Query ;
20
+ use CodeIgniter \Entity \Entity ;
20
21
use CodeIgniter \Exceptions \ModelException ;
21
22
use CodeIgniter \I18n \Time ;
22
23
use CodeIgniter \Pager \Pager ;
@@ -1684,8 +1685,11 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv
1684
1685
*/
1685
1686
protected function objectToRawArray ($ data , bool $ onlyChanged = true , bool $ recursive = false ): array
1686
1687
{
1688
+ if ($ data instanceof Entity) {
1689
+ $ properties = $ data ->toDatabase ($ onlyChanged , $ recursive );
1690
+ }
1687
1691
// @TODO Should define Interface or Class. Entity has toRawArray() now.
1688
- if (method_exists ($ data , 'toRawArray ' )) {
1692
+ elseif (method_exists ($ data , 'toRawArray ' )) {
1689
1693
$ properties = $ data ->toRawArray ($ onlyChanged , $ recursive );
1690
1694
} else {
1691
1695
$ mirror = new ReflectionClass ($ data );
@@ -1706,7 +1710,7 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
1706
1710
}
1707
1711
1708
1712
/**
1709
- * Transform data to array.
1713
+ * Transform data to array that can be save to database .
1710
1714
*
1711
1715
* @param array|object|null $data Data
1712
1716
* @param string $type Type of data (insert|update)
0 commit comments