|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; |
| 4 | + |
| 5 | +use Doctrine\Common\Collections\ArrayCollection; |
| 6 | +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
| 7 | + |
| 8 | +class GH1346Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @group GH1346Test |
| 12 | + */ |
| 13 | + public function testPublicProperty() |
| 14 | + { |
| 15 | + $referenced1 = new GH1346ReferencedDocument(); |
| 16 | + $referenced2 = new GH1346ReferencedDocument(); |
| 17 | + $gH1346Document = new GH1346Document(); |
| 18 | + $gH1346Document->addReference($referenced1); |
| 19 | + |
| 20 | + $this->dm->persist($referenced2); |
| 21 | + $this->dm->persist($referenced1); |
| 22 | + $this->dm->persist($gH1346Document); |
| 23 | + $this->dm->flush(); |
| 24 | + $this->dm->clear(); |
| 25 | + |
| 26 | + $gH1346Document = $this->dm->getRepository(__NAMESPACE__ . '\GH1346Document')->find($gH1346Document->getId()); |
| 27 | + $referenced2 = $this->dm->getRepository(__NAMESPACE__ . '\GH1346ReferencedDocument')->find($referenced2->getId()); |
| 28 | + |
| 29 | + $gH1346Document->addReference($referenced2); |
| 30 | + |
| 31 | + $this->dm->persist($gH1346Document); |
| 32 | + $this->dm->flush(); |
| 33 | + |
| 34 | + $this->assertEquals(2, $gH1346Document->getReferences()->count()); |
| 35 | + |
| 36 | + $this->dm->flush(); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | + |
| 41 | +/** |
| 42 | + * @ODM\Document |
| 43 | + */ |
| 44 | +class GH1346Document |
| 45 | +{ |
| 46 | + /** @ODM\Id */ |
| 47 | + protected $id; |
| 48 | + |
| 49 | + /** @ODM\ReferenceMany(targetDocument="GH1346ReferencedDocument") */ |
| 50 | + protected $references; |
| 51 | + |
| 52 | + public function __construct() |
| 53 | + { |
| 54 | + $this->references = new ArrayCollection(); |
| 55 | + } |
| 56 | + |
| 57 | + public function getId() |
| 58 | + { |
| 59 | + return $this->id; |
| 60 | + } |
| 61 | + |
| 62 | + public function addReference($otherReference) |
| 63 | + { |
| 64 | + $this->references->add($otherReference); |
| 65 | + } |
| 66 | + |
| 67 | + public function getReferences() |
| 68 | + { |
| 69 | + return $this->references; |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * @ODM\Document |
| 75 | + */ |
| 76 | +class GH1346ReferencedDocument |
| 77 | +{ |
| 78 | + /** @ODM\Field(type="string") */ |
| 79 | + public $test; |
| 80 | + |
| 81 | + /** @ODM\Id */ |
| 82 | + protected $id; |
| 83 | + |
| 84 | + public function setTest($test) |
| 85 | + { |
| 86 | + $this->test = $test; |
| 87 | + } |
| 88 | + |
| 89 | + public function getId() |
| 90 | + { |
| 91 | + return $this->id; |
| 92 | + } |
| 93 | +} |
0 commit comments