File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
src/Jenssegers/Mongodb/Relations Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ public function get()
141
141
public function save (Model $ model )
142
142
{
143
143
// Insert a new document.
144
- if (! $ model ->exists )
144
+ if ( ! $ model ->exists )
145
145
{
146
146
return $ this ->performInsert ($ model );
147
147
}
@@ -162,7 +162,7 @@ public function save(Model $model)
162
162
protected function performInsert (Model $ model )
163
163
{
164
164
// Create a new key.
165
- if (! isset ($ model ['_id ' ]))
165
+ if ( ! isset ( $ model [ ' _id ' ]) or empty ($ model ['_id ' ]))
166
166
{
167
167
$ model ->setAttribute ('_id ' , new MongoId );
168
168
}
Original file line number Diff line number Diff line change @@ -341,12 +341,18 @@ public function testEmbedsManySaveMany()
341
341
342
342
public function testEmbedsManyCreate ()
343
343
{
344
- $ user = User::create (array ('name ' => 'John Doe ' ));
345
- $ user ->addresses ()->create (array ('city ' => 'Bruxelles ' ));
344
+ $ user = User::create (array ());
345
+ $ address = $ user ->addresses ()->create (array ('city ' => 'Bruxelles ' ));
346
+ $ this ->assertInstanceOf ('Address ' , $ address );
347
+ $ this ->assertInstanceOf ('MongoID ' , $ address ->_id );
346
348
$ this ->assertEquals (array ('Bruxelles ' ), $ user ->addresses ->lists ('city ' ));
347
349
348
350
$ freshUser = User::find ($ user ->id );
349
351
$ this ->assertEquals (array ('Bruxelles ' ), $ freshUser ->addresses ->lists ('city ' ));
352
+
353
+ $ user = User::create (array ());
354
+ $ address = $ user ->addresses ()->create (array ('_id ' => '' , 'city ' => 'Bruxelles ' ));
355
+ $ this ->assertInstanceOf ('MongoID ' , $ address ->_id );
350
356
}
351
357
352
358
public function testEmbedsManyDestroy ()
You can’t perform that action at this time.
0 commit comments