Last active
December 24, 2015 14:09
-
-
Save maphe/6810339 to your computer and use it in GitHub Desktop.
Files to reproduce a bug on doctrine/mongodb-odm after commit cc4960a https://github.com/doctrine/mongodb-odm/commit/cc4960a581463e6a78beb981499d5e09d1257189
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Project\TestBundle\Document; | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | |
/** @MongoDB\Document(collection="odm_test_address") */ | |
class OdmTestAddress | |
{ | |
/** @MongoDB\Id */ | |
protected $id; | |
/** @MongoDB\String */ | |
protected $street; | |
/** | |
* Get id | |
* | |
* @return \MongoId $id | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set street | |
* | |
* @param string $street | |
*/ | |
public function setStreet($street) | |
{ | |
$this->street = $street; | |
} | |
/** | |
* Get street | |
* | |
* @return string $street | |
*/ | |
public function getStreet() | |
{ | |
return $this->street; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Project\TestBundle\Document; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | |
/** @MongoDB\Document(collection="odm_test_user") */ | |
class OdmTestUser | |
{ | |
/** @MongoDB\Id */ | |
protected $id; | |
/** @MongoDB\String */ | |
protected $name; | |
/** @MongoDB\ReferenceMany(targetDocument="Project\TestBundle\Document\OdmTestAddress", simple=true) */ | |
protected $addresses; | |
public function __construct() | |
{ | |
$this->addresses = new ArrayCollection(); | |
} | |
/** | |
* Get id | |
* | |
* @return \MongoId $id | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set name | |
* | |
* @param string $name | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
/** | |
* Get name | |
* | |
* @return string $name | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Add address | |
* | |
* @param OdmTestAddress $address | |
* | |
* @return $this | |
*/ | |
public function addAddress(OdmTestAddress $address) | |
{ | |
foreach ($this->addresses as $a) { | |
if ($a->getId() == $address->getId()) { | |
return $this; | |
} | |
} | |
$this->addresses[] = $address; | |
return $this; | |
} | |
/** | |
* Remove$address | |
* | |
* @param OdmTestAddress $address | |
* | |
* @return $this | |
*/ | |
public function removeAddress(OdmTestAddress $address) | |
{ | |
$this->addresses->removeElement($address); | |
return $this; | |
} | |
/** | |
* Get addresses | |
* | |
* @return ArrayCollection $addresses | |
*/ | |
public function getAddresses() | |
{ | |
return $this->addresses; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Project\TestBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller; | |
use Project\TestBundle\Document\OdmTestUser; | |
use Project\TestBundle\Document\OdmTestAddress; | |
class TestController extends BaseController | |
{ | |
public function testAction() | |
{ | |
$user = new OdmTestUser(); | |
$user->setName('user test 1'); | |
$address1 = new OdmTestAddress(); | |
$address1->setStreet('street test 1'); | |
$dm = $this->get('doctrine.odm.mongodb.document_manager'); | |
$dm->persist($address1); | |
$user->addAddress($address1); | |
$dm->persist($user); | |
$dm->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment