Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2163

Export entity data to array and create new entity by this array

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:

      Description

      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
      array(
      '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.

        Activity

        Anton created issue -
        Hide
        Anton added a comment -
        Show
        Anton added a comment - i write some weird code: http://stackoverflow.com/questions/13507300/doctrine2-export-entity-to-array/13522452#13522452 please, take a look.
        Hide
        Marco Pivetta added a comment -

        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

        Show
        Marco Pivetta added a comment - 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
        Hide
        Marco Pivetta added a comment -

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

        Show
        Marco Pivetta added a comment - Anton this is not the correct approach to the problem. Serialization/unserialization is a problem related to (probably) Doctrine\Common.
        Marco Pivetta made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Won't Fix [ 2 ]
        Hide
        Anton added a comment -

        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?

        Show
        Anton added a comment - 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?

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2163, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Anton
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: