serialize/unserialize fields automatically

24 views
Skip to first unread message

Eric Risler

unread,
Feb 12, 2014, 11:04:30 PM2/12/14
to pommp...@googlegroups.com
Hi,

How would we go about automatically unserializing one or more fields for an entity automatically? We store php arrays in "text" fields but would like these to be auto-unserialzed whenever they are read from the db and serialized whenever written.

Thanks.

Grégoire Hubert

unread,
Feb 13, 2014, 1:28:08 AM2/13/14
to pommp...@googlegroups.com
Hi,

I can see 2 ways of doing it. The simplest one would be entities to
store serialized arrays as such. Getters and setter would provide
un/serialization on the fly. There are many drawbacks since arrays
cannot be manipulated.

The other (and cleaner) way would be
1° create a SerializedArray converter
2° associate it with a "serialized_array" type
3° assign those fields with this type. You will have to manually tell
Pomm which fields are using this type since Postgresql will not know
anything about it.

1° Your SerializedArrayConverter class must implement
\Pomm\Converter\ConverterInterface interface

2° Register the converter and associate it with a serialized_array type:

$database->registerConverter('SerializedArray', new
SerializedArrayConverter(), array('serialized_array'));

3° In your entities mapping classes, override postgres definition for this type:

class MyEntityMap extends BaseMyEntityMap
{
public function initialize()
{
parent::initialize();

$this->addField('my_field', 'serialized_array');
....
}
}

Trying this solution did highlite a bug :
https://github.com/chanmix51/Pomm/issues/127

Cheers
--
Grégoire HUBERT
Pomm http://www.pomm-project.org

Eric Risler - MYNT Partners Inc.

unread,
Feb 13, 2014, 1:35:15 AM2/13/14
to pommp...@googlegroups.com
I was looking at using converters in the manner you mention but noticed the exception as well. I've commented on your issue thread. Thanks.


--
You received this message because you are subscribed to a topic in the Google Groups "PommProject" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pommproject/FaCGbC2p1Bg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pommproject...@googlegroups.com.
Visit this group at http://groups.google.com/group/pommproject.
For more options, visit https://groups.google.com/groups/opt_out.



--


Eric Risler

MYNT Partners Inc.

 

Toronto (Direct):     +1 (647) 478-5535

Toll-Free (Office):   +1 (877) 832-1262

E-mail:                      eri...@myntpartners.com

Skype:                       eric.risler

 

157 Adelaide Street West #429

Toronto, Ontario

M5H 4E7

 

This e-mail and any attachments to it are confidential.  Any dissemination, distribution, copying or other unauthorized use of this e-mail is prohibited. If you have received this e-mail in error please notify the sender by reply e-mail and delete this message and any attachments to it immediately. 

 

Grégoire Hubert

unread,
Feb 13, 2014, 9:52:02 AM2/13/14
to pommp...@googlegroups.com
The issue has been solved.
> You received this message because you are subscribed to the Google Groups
> "PommProject" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Grégoire HUBERT
Pomm non ORM http://pomm.coolkeums.org
Reply all
Reply to author
Forward
0 new messages