diff options
Diffstat (limited to 'Digitigrade/Model.php')
| -rw-r--r-- | Digitigrade/Model.php | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php index 14d025d..6e87860 100644 --- a/Digitigrade/Model.php +++ b/Digitigrade/Model.php @@ -81,6 +81,9 @@ abstract class Model { } elseif (is_array($value)) { // arrays ought to be handled separately when saving (different db table) $discarded = true; + } elseif ($value instanceof \stdClass) { + // probably json + $value = json_encode($value); } elseif ($value == null && $pName == 'id') { // don't overwrite an existing primary key with null .. // this is kinda janky but it hopefully will work @@ -118,6 +121,9 @@ abstract class Model { } elseif (is_subclass_of($typeClass, Model::class) && is_int($value)) { // if it's another model we can try to look it up by id automatically $obj->{$name} = $typeClass::find($value); + } elseif (is_a($typeClass, \stdClass::class, true)) { + // if it's a stdclass it's usually json + $obj->{$name} = json_decode($value); } else { // otherwise try to instantiate the correct class and pass it the simple value $obj->{$name} = new $typeClass($value); |
