Skip to content

Commit c5576d9

Browse files
committed
fix: toRawArray() behavior
The previous code no longer makes sense.
1 parent 5b13b24 commit c5576d9

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

system/Entity/Entity.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu
204204
}
205205

206206
/**
207-
* Returns the raw values of the current attributes.
207+
* Returns the values for database of the current attributes.
208208
*
209209
* @param bool $onlyChanged If true, only return values that have changed since object creation
210210
* @param bool $recursive If true, inner entities will be cast as array as well.
@@ -213,41 +213,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu
213213
*/
214214
public function toRawArray(bool $onlyChanged = false, bool $recursive = false): array
215215
{
216-
$return = [];
217-
218-
if (! $onlyChanged) {
219-
if ($recursive) {
220-
return array_map(static function ($value) use ($onlyChanged, $recursive) {
221-
if ($value instanceof self) {
222-
$value = $value->toRawArray($onlyChanged, $recursive);
223-
} elseif (is_callable([$value, 'toRawArray'])) {
224-
$value = $value->toRawArray();
225-
}
226-
227-
return $value;
228-
}, $this->attributes);
229-
}
230-
231-
return $this->attributes;
232-
}
233-
234-
foreach ($this->attributes as $key => $value) {
235-
if (! $this->hasChanged($key)) {
236-
continue;
237-
}
238-
239-
if ($recursive) {
240-
if ($value instanceof self) {
241-
$value = $value->toRawArray($onlyChanged, $recursive);
242-
} elseif (is_callable([$value, 'toRawArray'])) {
243-
$value = $value->toRawArray();
244-
}
245-
}
246-
247-
$return[$key] = $value;
248-
}
249-
250-
return $return;
216+
return $this->toDatabase($onlyChanged, $recursive);
251217
}
252218

253219
/**

0 commit comments

Comments
 (0)