php - Doctrine life cycle event and serializing JSON -
i have situation need serialize attribute of entity json database. i'm aware can create own data type purpose , works well, however, prefer understand "how" able make original method work correctly.
the problem encountered:
i have few entities in store "meta" data json in mysql database. marked entity's attribute type text
, implemented prepersist
, preupdate
life cycle events:
public function prepersist(preupdateeventargs $eventargs) { $this->meta = json_encode($this->meta); } public function postpersist(preupdateeventargs $eventargs) { $this->meta = json_decode($this->meta, true); }
the life cycle events called in following scenarios (i happen using yaml entity mapping rather annotations):
lifecyclecallbacks: prepersist: [ prepersist ] postpersist: [ postpersist ] preupdate: [ prepersist ] postupdate: [ postpersist ] postload: [ postpersist ]
the $meta
attribute array
, when entity persisted serialized json , after has been persisted turned array
. pretty simply.
however, noticed entity implements technique always persisted, regardless if content of $meta
has changed or not. i.e. $eventargs
parameter passed each of life cycle handlers marks $meta
attribute of entity changed.
what think happening doctrine compares value of entity against same value of previous loaded proxy of entity decide if attribute of entity has changed or not , proxy version of entity has serialized json string , actual entity has php array
, entity marked changed.
my question is, how can make sure doctrine compares correct representation of value? i.e. compare either array
array
or compare serialized json string serialized json string?
wiki
Comments
Post a Comment