diff --git a/phalcon/Mvc/Model.zep b/phalcon/Mvc/Model.zep index 50a0b459165..01a4613de34 100644 --- a/phalcon/Mvc/Model.zep +++ b/phalcon/Mvc/Model.zep @@ -2635,28 +2635,23 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface, /** * Use the standard serialize function to serialize the array data */ - var attributes, snapshot, manager; + var attributes, manager, dirtyState, snapshot = null; let attributes = this->toArray(), + dirtyState = this->dirtyState, manager = this->getModelsManager(); - if manager->isKeepingSnapshots(this) { + if manager->isKeepingSnapshots(this) && this->snapshot != null && attributes != this->snapshot { let snapshot = this->snapshot; - - /** - * If attributes is not the same as snapshot then save snapshot too - */ - if snapshot != null && attributes != snapshot { - return serialize( - [ - "_attributes": attributes, - "snapshot": snapshot - ] - ); - } } - return serialize(attributes); + return serialize( + [ + "properties": attributes, + "snapshot": snapshot, + "dirtyState": dirtyState + ] + ); } /** @@ -2664,7 +2659,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface, */ public function unserialize(var data) { - var attributes, container, manager, key, value, snapshot; + var attributes, container, manager, key, value, snapshot, properties, dirtyState; let attributes = unserialize(data); @@ -2708,20 +2703,36 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface, */ manager->initialize(this); - if manager->isKeepingSnapshots(this) { - if fetch snapshot, attributes["snapshot"] { - let this->snapshot = snapshot; - let attributes = attributes["_attributes"]; - } else { - let this->snapshot = attributes; + /** + * Fetch serialized props + */ + if fetch properties, attributes["properties"] { + /** + * Update the objects properties + */ + for key, value in properties { + let this->{key} = value; } + } else { + let properties = []; + } + + /** + * Fetch serialized dirtyState + */ + if fetch dirtyState, attributes["dirtyState"] { + let this->dirtyState = dirtyState; } /** - * Update the objects attributes + * Fetch serialized snapshot when option is active */ - for key, value in attributes { - let this->{key} = value; + if manager->isKeepingSnapshots(this) { + if fetch snapshot, attributes["snapshot"] { + let this->snapshot = snapshot; + } else { + let this->snapshot = properties; + } } } }