1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;

require_once __DIR__ . '/../../../../../../TestInit.php';

use Doctrine\Common\Collections\ArrayCollection;

class MODM66Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{

    public function testTest()
    {
        $b1 = new B('first');
        $a = new A(array($b1));
        $this->dm->persist($a);
        $this->dm->flush();
        $b2 = new B('second');
        $a->getB()->add($b2);
        $this->dm->flush();

        $this->dm->refresh($a);
        $b = $a->getB()->toArray();

        $this->assertEquals(2, count($b));

        $this->assertEquals(array(
            $b1->getId(), $b2->getId()
        ), array(
            $b[0]->getId(), $b[1]->getId()
        ));
    }

}

/** @Document(db="tests", collection="tests") */
class A
{

    /** @Id */
    protected $id;
    /** @ReferenceMany(targetDocument="b", cascade="all") */
    protected $b;

    function __construct($b)
    {
        $this->b = new ArrayCollection($b);
    }

    function getB()
    {
        return $this->b;
    }

}

/** @Document(db="tests", collection="tests2") */
class B
{

    /** @Id */
    protected $id;
    /** @String */
    protected $tmp;

    function __construct($v)
    {
        $this->tmp = $v;
    }

    public function getId()
    {
        return $this->id;
    }

}