File tree 4 files changed +29
-1
lines changed
Doctrine/ODM/MongoDB/Tests/Functional
4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -840,7 +840,11 @@ function ($assoc) { return empty($assoc['notSaved']); }
840
840
$ oid2 = spl_object_hash ($ obj );
841
841
842
842
if (isset ($ this ->documentChangeSets [$ oid2 ])) {
843
- $ this ->documentChangeSets [$ oid ][$ mapping ['fieldName ' ]] = array ($ value , $ value );
843
+ if (empty ($ this ->documentChangeSets [$ oid ][$ mapping ['fieldName ' ]])) {
844
+ // instance of $value is the same as it was previously otherwise there would be
845
+ // change set already in place
846
+ $ this ->documentChangeSets [$ oid ][$ mapping ['fieldName ' ]] = array ($ value , $ value );
847
+ }
844
848
845
849
if ( ! $ isNewDocument ) {
846
850
$ this ->scheduleForUpdate ($ document );
Original file line number Diff line number Diff line change 2
2
3
3
namespace Doctrine \ODM \MongoDB \Tests \Functional ;
4
4
5
+ use Doctrine \Common \Collections \ArrayCollection ;
5
6
use Documents \Bars \Bar ;
6
7
use Documents \Bars \Location ;
7
8
use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
@@ -65,6 +66,14 @@ public function testCollections()
65
66
$ bar = $ this ->dm ->find ('Documents\Bars\Bar ' , $ bar ->getId ());
66
67
$ locations = $ bar ->getLocations ();
67
68
$ this ->assertEquals (0 , count ($ locations ));
69
+ $ this ->dm ->flush ();
70
+
71
+ $ bar ->setLocations (new ArrayCollection ([ new Location ('Cracow ' ) ]));
72
+ $ this ->uow ->computeChangeSets ();
73
+ $ changeSet = $ this ->uow ->getDocumentChangeSet ($ bar );
74
+ $ this ->assertNotEmpty ($ changeSet ['locations ' ]);
75
+ $ this ->assertSame ($ locations , $ changeSet ['locations ' ][0 ]);
76
+ $ this ->assertSame ($ bar ->getLocations (), $ changeSet ['locations ' ][1 ]);
68
77
}
69
78
70
79
public function testCreateCollections ()
Original file line number Diff line number Diff line change @@ -108,6 +108,16 @@ public function testOneEmbedded()
108
108
->getSingleResult ();
109
109
$ this ->assertNotNull ($ user );
110
110
$ this ->assertEquals ($ addressClone , $ user ->getAddress ());
111
+
112
+ $ oldAddress = $ user ->getAddress ();
113
+ $ address = new Address ();
114
+ $ address ->setAddress ('Someplace else ' );
115
+ $ user ->setAddress ($ address );
116
+ $ this ->uow ->computeChangeSets ();
117
+ $ changeSet = $ this ->uow ->getDocumentChangeSet ($ user );
118
+ $ this ->assertNotEmpty ($ changeSet ['address ' ]);
119
+ $ this ->assertSame ($ oldAddress , $ changeSet ['address ' ][0 ]);
120
+ $ this ->assertSame ($ user ->getAddress (), $ changeSet ['address ' ][1 ]);
111
121
}
112
122
113
123
public function testRemoveOneEmbedded ()
Original file line number Diff line number Diff line change @@ -45,4 +45,9 @@ public function getLocations()
45
45
{
46
46
return $ this ->locations ;
47
47
}
48
+
49
+ public function setLocations ($ locations )
50
+ {
51
+ $ this ->locations = $ locations ;
52
+ }
48
53
}
You can’t perform that action at this time.
0 commit comments