Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1734

Uninitialized proxies cannot be serialized properly

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: 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.

        Issue Links

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: