You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An Eloquent model and Query builder with support for MongoDB, inspired by LMongo, but using the original Laravel methods. *This library extends the original Laravel classes, so it uses exactly the same methods.*
6
+
An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.*
7
7
8
8
### Upgrading from v1 to v2
9
9
10
-
In this new version, embedded documents are no longer saved to the parent model using an attribute with a leading underscore. If you have a relation like `embedsMany('Book')`, these books are now stored under `$model['books']` instead of `$model['_books']`. This was changed so that embedded relations are less confusing for new developers.
10
+
In this new version, embedded documents are no longer saved to the parent model using an attribute with a leading underscore. If you have a relation like `embedsMany('Book')`, these books are now stored under `$model['books']` instead of `$model['_books']`. This was changed to make embedded relations less confusing for new developers.
11
11
12
-
If you want to upgrade to this new version, without having to change all your existing database objects, you can modify your relations to use a local key including the underscore:
12
+
If you want to upgrade to this new version without having to change all your existing database objects, you can modify your embedded relations to use a non-default local key including the underscore:
13
13
14
14
$this->embedsMany('Book', '_books');
15
15
16
-
You can see the changelog at https://github.com/jenssegers/laravel-mongodb/releases/tag/v2.0.0
16
+
Read the full changelog at https://github.com/jenssegers/laravel-mongodb/releases/tag/v2.0.0
17
17
18
18
Installation
19
19
------------
@@ -75,7 +75,7 @@ Tell your model to use the MongoDB model and set the collection (alias for table
75
75
76
76
}
77
77
78
-
If you are using a different database driver as the default one, you will need to specify the mongodb connection within your model by changing the `connection` property:
78
+
If you are using a different database driver as the default one, you will need to specify the mongodb connection name within your model by changing the `connection` property:
79
79
80
80
use Jenssegers\Mongodb\Model as Eloquent;
81
81
@@ -104,15 +104,15 @@ This will allow you to use your registered alias like:
104
104
Query Builder
105
105
-------------
106
106
107
-
The database driver plugs right into the original query builder. When using mongodb connections you will be able to build fluent queries to perform database operations. For your convenience, there is a `collection` alias for `table` as well as some additional mongodb specific operators/operations.
107
+
The database driver plugs right into the original query builder. When using mongodb connections, you will be able to build fluent queries to perform database operations. For your convenience, there is a `collection` alias for `table` as well as some additional mongodb specific operators/operations.
Read more about the query builder on http://laravel.com/docs/queries
117
117
118
118
Schema
@@ -429,7 +429,7 @@ Other relations are not yet supported, but may be added in the future. Read more
429
429
430
430
### EmbedsMany Relations
431
431
432
-
If you want to embed documents, rather than referencing them, you can use the `embedsMany` relation. This relation is similar to the `hasMany` relation, but embeds the models in the parent object.
432
+
If you want to embed models, rather than referencing them, you can use the `embedsMany` relation. This relation is similar to the `hasMany` relation, but embeds the models inside the parent object.
433
433
434
434
use Jenssegers\Mongodb\Model as Eloquent;
435
435
@@ -442,15 +442,15 @@ If you want to embed documents, rather than referencing them, you can use the `e
442
442
443
443
}
444
444
445
-
Now we can access the user's books through the dynamic property:
445
+
You access the embedded models through the dynamic property:
446
446
447
447
$books = User::first()->books;
448
448
449
-
When using embedded documents, there will also be an inverse relation available:
449
+
The inverse relation is auto*magically* available, you don't need to define this reverse relation.
450
450
451
451
$user = $book->user;
452
452
453
-
Inserting and updating embedded documents works just like the `belongsTo` relation:
453
+
Inserting and updating embedded models works similar to the `hasMany` relation:
454
454
455
455
$book = new Book(array('title' => 'A Game of Thrones'));
456
456
@@ -460,39 +460,46 @@ Inserting and updating embedded documents works just like the `belongsTo` relati
460
460
// or
461
461
$book = $user->books()->create(array('title' => 'A Game of Thrones'))
462
462
463
-
Modifying and saving embedded documents is as easy as (available since release 2.0.0):
463
+
You can update embedded models using their `save` method (available since release 2.0.0):
464
464
465
465
$book = $user->books()->first();
466
466
467
467
$book->title = 'A Game of Thrones';
468
468
469
469
$book->save();
470
470
471
-
You can remove an embedded document by using the `destroy()` method on the relation, or the `delete` method on the model (available since release 2.0.0):
471
+
You can remove an embedded model by using the `destroy` method on the relation, or the `delete` method on the model (available since release 2.0.0):
472
472
473
473
$book = $user->books()->first();
474
474
475
475
$book->delete();
476
476
// or
477
477
$user->books()->destroy($book);
478
478
479
-
If you want to add or remove embedded documents, without persistence, you can use the `associate` and `dissociate` methods. To write the changes to the database, simply save the parent object:
479
+
If you want to add or remove an embedded model, without touching the database, you can use the `associate` and `dissociate` methods. To eventually write the changes to the database, save the parent object:
480
480
481
481
$user->books()->associate($book);
482
482
483
483
$user->save();
484
484
485
-
Again, you may override the conventional local key by passing a second argument to the embedsMany method:
485
+
Like other relations, embedsMany assumes the local key of the relationship based on the model name. You can override the default local key by passing a second argument to the embedsMany method:
486
486
487
487
return $this->embedsMany('Book', 'local_key');
488
488
489
-
Embedded relations will return a Collection of embedded items instead of a query builder. To simulate a more query-like behavior, embedded relations return a modified version of the Collection class with support for the following operations: `where($key, $operator, $value)` and `orderBy($key, $direction)`. This allows you to do query the collection results like this:
489
+
Embedded relations will return a Collection of embedded items instead of a query builder. To allow a more query-like behavior, embedded relations will return a modified version of the Collection class with support for the following operations:
490
+
491
+
- where($key, $operator, $value)
492
+
- orderBy($key, $direction)
493
+
494
+
This allows you to execute simple queries on the collection results:
**Note:** Because embedded models are not stored in a separate collection, you can not query all of embedded models. You will always have to access them through the parent model.
499
+
493
500
### EmbedsOne Relations
494
501
495
-
There is also an EmbedsOne relation, which works similar to the EmbedsMany relation, but only stores one embedded model.
502
+
The embedsOne relation is similar to the EmbedsMany relation, but only embeds a single model.
496
503
497
504
use Jenssegers\Mongodb\Model as Eloquent;
498
505
@@ -505,11 +512,11 @@ There is also an EmbedsOne relation, which works similar to the EmbedsMany relat
505
512
506
513
}
507
514
508
-
Now we can access the book's author through the dynamic property:
515
+
You access the embedded models through the dynamic property:
509
516
510
517
$author = Book::first()->author;
511
518
512
-
Inserting and updating the embedded document works just like the `embedsMany` relation:
519
+
Inserting and updating embedded models works similar to the `hasOne` relation:
513
520
514
521
$author = new Author(array('name' => 'John Doe'));
515
522
@@ -519,14 +526,14 @@ Inserting and updating the embedded document works just like the `embedsMany` re
0 commit comments