github mongodb/laravel-mongodb v2.0.0

latest releases: 5.1.0, 5.0.2, 5.0.1...
10 years ago

Embedded Relations

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.

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:

$this->embedsMany('Book', '_books');

Additionally, working with embedded models has become a lot easier. With this release, you can use the update, save and delete methods on the embedded models directly, instead of going through the relation instance of the parent model. Example:

$user = User::create(array('name' => 'John Doe'));
$address = $user->addresses()->create(array('city' => 'New York'));

$address->city = 'Paris';
$address->save();

Embedded relations will return a Collection of embedded items instead of a query builder. To allow a more query-like behavior, embedded relations return a modified version of the Collection class with support for the following additional operations:

  • where($key, $operator, $value)
  • whereIn($key, $values) and whereNotIn($key, $values)
  • whereBetween($key, $values) and whereNotBetween($key, $values)
  • whereNull($key) and whereNotNull($key)
  • orderBy($key, $direction)
  • oldest() and latest()
  • limit($value)
  • offset($value)
  • skip($value)

This allows you to execute basic where queries on the collection results.

Embedded relations should now handle deeply nested relations a lot better. However, this does not produce optimal database queries, so use it with caution.

Model

The model class now supports keys in dot notation. This was added to fix an issue where local and/or foreign keys for relations were inside a sub-object.

Push and pull operations now also change the internal attributes of the model, opposed to only executing a query in the previous version.

Query builder

The query builder now supports projections using the project method. The array that you pass to this method will be passed to the find queries.

You can now also set a timeout value for the Cursor objects using the timeout method. This will automatically set the timeout on the Cursor result before converting it to an array of results.

Belongs to many

The belongs to many relation was updated and now automatically pushes/pulls the id's to/from the model object. This prevents duplicate ids from being stored.

Password reminders

The included ReminderServiceProvider was modified so that password reminders are saved with a MongoDate.

Don't miss a new laravel-mongodb release

NewReleases is sending notifications on new releases.