@@ -269,4 +269,69 @@ public function testSortReferenceManyOwningSide()
269269 $ this ->assertEquals ('Group 2 ' , $ groups [0 ]->getName ());
270270 $ this ->assertEquals ('Group 1 ' , $ groups [1 ]->getName ());
271271 }
272- }
272+
273+ /**
274+ * Fixes: Argument 1 passed to Doctrine\ODM\MongoDB\Persisters\DocumentPersister::prepareQueryOrNewObj() must be an array, null given
275+ *
276+ * @expectedException \Doctrine\ODM\MongoDB\DocumentNotFoundException
277+ * @expectedExceptionMessage The "Proxies\__CG__\Documents\Profile" document with identifier "" could not be found.
278+ */
279+ public function testReferenceOneWithNullId ()
280+ {
281+ $ profile = new Profile ();
282+ $ user = new User ();
283+ $ user ->setProfile ($ profile );
284+
285+ $ this ->dm ->persist ($ profile );
286+ $ this ->dm ->persist ($ user );
287+ $ this ->dm ->flush ();
288+ $ this ->dm ->clear ();
289+
290+ $ collection = $ this ->dm ->getDocumentCollection (get_class ($ user ));
291+
292+ $ collection ->update (
293+ array ('_id ' => new \MongoId ($ user ->getId ())),
294+ array ('$set ' => array (
295+ 'profile.$id ' => null ,
296+ ))
297+ );
298+
299+ $ user = $ this ->dm ->find (get_class ($ user ), $ user ->getId ());
300+ $ profile = $ user ->getProfile ();
301+ $ profile ->__load ();
302+ }
303+
304+ /**
305+ * Fixes: Argument 1 passed to Doctrine\ODM\MongoDB\Persisters\DocumentPersister::prepareQueryOrNewObj() must be an array, null given
306+ *
307+ * @expectedException \Doctrine\ODM\MongoDB\DocumentNotFoundException
308+ * @expectedExceptionMessage The "Proxies\__CG__\Documents\Group" document with identifier "" could not be found.
309+ */
310+ public function testReferenceManyWithNullId ()
311+ {
312+ $ user = new User ();
313+ $ user ->addGroup (new Group ('Group ' ));
314+
315+ $ this ->dm ->persist ($ user );
316+ $ this ->dm ->flush ();
317+ $ this ->dm ->clear ();
318+
319+ $ collection = $ this ->dm ->getDocumentCollection (get_class ($ user ));
320+
321+ $ collection ->update (
322+ array ('_id ' => new \MongoId ($ user ->getId ())),
323+ array ('$set ' => array (
324+ 'groups.0.$id ' => null ,
325+ ))
326+ );
327+
328+ $ user = $ this ->dm ->find (get_class ($ user ), $ user ->getId ());
329+ $ groups = $ user ->getGroups ();
330+
331+ $ this ->assertEquals (1 , count ($ groups ));
332+
333+ foreach ($ groups as $ group ) {
334+ $ group ->__load ();
335+ }
336+ }
337+ }
0 commit comments