예제 #1
0
 public function setAddress(CmsAddress $address)
 {
     if ($this->address !== $address) {
         $this->address = $address;
         $address->setUser($this);
     }
 }
 public function testUninitializedLazyAssociationsAreIgnoredOnMerge()
 {
     $user = new CmsUser();
     $user->name = 'Guilherme';
     $user->username = '******';
     $user->status = 'developer';
     $address = new CmsAddress();
     $address->city = 'Berlin';
     $address->country = 'Germany';
     $address->street = 'Sesamestreet';
     $address->zip = 12345;
     $address->setUser($user);
     $this->dm->persist($address);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $address2 = $this->dm->find(get_class($address), $address->id);
     $this->assertTrue($address2->user instanceof \Doctrine\ODM\MongoDB\Proxy\Proxy);
     $this->assertFalse($address2->user->__isInitialized__);
     $detachedAddress2 = unserialize(serialize($address2));
     $this->assertTrue($detachedAddress2->user instanceof \Doctrine\ODM\MongoDB\Proxy\Proxy);
     $this->assertFalse($detachedAddress2->user->__isInitialized__);
     $managedAddress2 = $this->dm->merge($detachedAddress2);
     $this->assertTrue($managedAddress2->user instanceof \Doctrine\ODM\MongoDB\Proxy\Proxy);
     $this->assertFalse($managedAddress2->user === $detachedAddress2->user);
     $this->assertFalse($managedAddress2->user->__isInitialized__);
 }