[DDC-2163] Export entity data to array and create new entity by this array Created: 23/Nov/12  Updated: 27/Nov/12  Resolved: 23/Nov/12

Status: Closed
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Anton Assignee: Benjamin Eberlei
Resolution: Won't Fix Votes: 0
Labels: serialize


Entity serialization is really pain operation for doctrine2 entities, but why we need serialization? If we may just get array of table's row for entity and store this array anywhere!

For example, we have Entity:

id, category_id, title

(where category_id is many to one to Category entity)

If we will able to get just array from entity like
'id' => 1,
'category_id' => 2,
'title' => 'Some title'
That's all!

I look at code and find a place where table row converted to object: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php#L341

This method is protected, so we can't call it directly. Can we change it to public?

Another question how we can get this raw values array from entity. I found method https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L2692 but it return data with related entities.

Comment by Anton [ 23/Nov/12 ]

i write some weird code: http://stackoverflow.com/questions/13507300/doctrine2-export-entity-to-array/13522452#13522452
please, take a look.

Comment by Marco Pivetta [ 23/Nov/12 ]

Anton the namespace `Internal` is there for a reason. If you want to convert entities to array or the opposite, please use either JMS Serializer, Symfony Serializer or Zend\StdLib\Hydrator with DoctrineModule\StdLib\Hydrator.

Currently, we don't support serialization

Comment by Marco Pivetta [ 23/Nov/12 ]

Anton this is not the correct approach to the problem. Serialization/unserialization is a problem related to (probably) Doctrine\Common.

Comment by Anton [ 27/Nov/12 ]

Marco Pivetta, thanks for reply. With JMSSerializer or Symfony serializer can i later insert\update object in db? I see in sources, that UnitOfWork get changeset for each entity. How doctrine2 knows which properties of serialized\deserialized entitiy was changed?

Generated at Tue Dec 01 18:52:23 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.