Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1734

Uninitialized proxies cannot be serialized properly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I have the following entity:

      class Currency
      {
          /** @Id @Column(type="string") */
          protected $code;
              
          /** @Column(type="string") */    
          protected $name;
      }
      

      When I serialize an object graph which references a Currency proxy, but this proxy is initialized, then this works as expected:

      O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:1;s:7:"*code";s:3:"USD";s:7:"*name";s:20:"United States Dollar";}
      

      However, if the proxy is not initialized, then all properties are serialized as null, and the identity is lost:

      O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:0;s:7:"*code";N;s:7:"*name";N;}
      

      That makes a merge() impossible once stored in a session, as the identity of the entity is now unknown.

      I think the solution might be:

      • either to have the proxy's $_identity field serialized as well
      • or to have the $code (identity field) populated when the proxy is created.

        Activity

        Show
        Marco Pivetta added a comment - Matthieu Napoli I deployed a fix in DCOM-96 ( https://github.com/doctrine/doctrine2/pull/406 https://github.com/Ocramius/doctrine2/commit/1424cc781277a4f8183229c5e8d838724e1ca879 )
        Hide
        Matthieu Napoli added a comment -

        Marco Pivetta fantastic!

        Show
        Matthieu Napoli added a comment - Marco Pivetta fantastic!
        Hide
        Benjamin Eberlei added a comment -

        A related Github Pull-Request [GH-247] was opened
        https://github.com/doctrine/common/pull/247

        Show
        Benjamin Eberlei added a comment - A related Github Pull-Request [GH-247] was opened https://github.com/doctrine/common/pull/247
        Hide
        Benjamin Eberlei added a comment -

        A related Github Pull-Request [GH-247] was closed
        https://github.com/doctrine/common/pull/247

        Show
        Benjamin Eberlei added a comment - A related Github Pull-Request [GH-247] was closed https://github.com/doctrine/common/pull/247
        Hide
        Marco Pivetta added a comment -

        Resolved in DCOM-96

        Show
        Marco Pivetta added a comment - Resolved in DCOM-96

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Benjamin Morel
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: