Commit 809c3a73 authored by Dmitry Borzyonok's avatar Dmitry Borzyonok

Add L5.5 support

parent c0cae3e1
...@@ -11,17 +11,18 @@ ...@@ -11,17 +11,18 @@
], ],
"license" : "MIT", "license" : "MIT",
"require": { "require": {
"illuminate/support": "^5.1", "illuminate/support": "^5.5",
"illuminate/container": "^5.1", "illuminate/container": "^5.5",
"illuminate/database": "^5.1", "illuminate/database": "^5.5",
"illuminate/events": "^5.1", "illuminate/events": "^5.5",
"mongodb/mongodb": "^1.0.0" "mongodb/mongodb": "^1.0.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.0|^6.0", "phpunit/phpunit": "^6.0",
"orchestra/testbench": "^3.1", "orchestra/testbench": "^3.1",
"mockery/mockery": "^0.9", "mockery/mockery": "^0.9",
"satooshi/php-coveralls": "^1.0" "satooshi/php-coveralls": "^1.0",
"doctrine/dbal": "^2.6"
}, },
"autoload": { "autoload": {
"psr-0": { "psr-0": {
......
...@@ -27,7 +27,7 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository ...@@ -27,7 +27,7 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
$date = $token['created_at']->toDateTime(); $date = $token['created_at']->toDateTime();
$date->setTimezone(new DateTimeZone(date_default_timezone_get())); $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$token['created_at'] = $date->format('Y-m-d H:i:s'); $token['created_at'] = $date->format('Y-m-d H:i:s');
} elseif (is_array($token['created_at']) and isset($token['created_at']['date'])) { } elseif (is_array($token['created_at']) && isset($token['created_at']['date'])) {
$date = new DateTime($token['created_at']['date'], new DateTimeZone(isset($token['created_at']['timezone']) ? $token['created_at']['timezone'] : 'UTC')); $date = new DateTime($token['created_at']['date'], new DateTimeZone(isset($token['created_at']['timezone']) ? $token['created_at']['timezone'] : 'UTC'));
$date->setTimezone(new DateTimeZone(date_default_timezone_get())); $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$token['created_at'] = $date->format('Y-m-d H:i:s'); $token['created_at'] = $date->format('Y-m-d H:i:s');
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Jenssegers\Mongodb; namespace Jenssegers\Mongodb;
use Illuminate\Database\Connection as BaseConnection; use Illuminate\Database\Connection as BaseConnection;
use Illuminate\Support\Arr;
use MongoDB\Client; use MongoDB\Client;
class Connection extends BaseConnection class Connection extends BaseConnection
...@@ -34,7 +35,7 @@ class Connection extends BaseConnection ...@@ -34,7 +35,7 @@ class Connection extends BaseConnection
$dsn = $this->getDsn($config); $dsn = $this->getDsn($config);
// You can pass options directly to the MongoDB constructor // You can pass options directly to the MongoDB constructor
$options = array_get($config, 'options', []); $options = Arr::get($config, 'options', []);
// Create the connection // Create the connection
$this->connection = $this->createConnection($dsn, $config, $options); $this->connection = $this->createConnection($dsn, $config, $options);
......
...@@ -162,10 +162,18 @@ class Builder extends EloquentBuilder ...@@ -162,10 +162,18 @@ class Builder extends EloquentBuilder
return $this->model->newFromBuilder((array) $results); return $this->model->newFromBuilder((array) $results);
} // The result is a single object. } // The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results)) { elseif (is_array($results) && array_key_exists('_id', $results)) {
return $this->model->newFromBuilder((array) $results); return $this->model->newFromBuilder((array) $results);
} }
return $results; return $results;
} }
/**
* @return \Illuminate\Database\ConnectionInterface
*/
public function getConnection()
{
return $this->query->getConnection();
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Jenssegers\Mongodb\Eloquent; namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Support\Str;
use Jenssegers\Mongodb\Relations\EmbedsMany; use Jenssegers\Mongodb\Relations\EmbedsMany;
use Jenssegers\Mongodb\Relations\EmbedsOne; use Jenssegers\Mongodb\Relations\EmbedsOne;
...@@ -32,7 +33,7 @@ trait EmbedsRelations ...@@ -32,7 +33,7 @@ trait EmbedsRelations
} }
if (is_null($foreignKey)) { if (is_null($foreignKey)) {
$foreignKey = snake_case(class_basename($this)); $foreignKey = Str::snake(class_basename($this));
} }
$query = $this->newQuery(); $query = $this->newQuery();
...@@ -67,7 +68,7 @@ trait EmbedsRelations ...@@ -67,7 +68,7 @@ trait EmbedsRelations
} }
if (is_null($foreignKey)) { if (is_null($foreignKey)) {
$foreignKey = snake_case(class_basename($this)); $foreignKey = Str::snake(class_basename($this));
} }
$query = $this->newQuery(); $query = $this->newQuery();
......
...@@ -214,11 +214,20 @@ trait HybridRelations ...@@ -214,11 +214,20 @@ trait HybridRelations
* @param string $collection * @param string $collection
* @param string $foreignKey * @param string $foreignKey
* @param string $otherKey * @param string $otherKey
* @param string $parentKey
* @param string $relatedKey
* @param string $relation * @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/ */
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null) public function belongsToMany(
{ $related,
$collection = null,
$foreignKey = null,
$otherKey = null,
$parentKey = null,
$relatedKey = null,
$relation = null
) {
// If no relationship name was passed, we will pull backtraces to get the // If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the // name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply. // title of this relation since that is a great convention to apply.
...@@ -228,7 +237,15 @@ trait HybridRelations ...@@ -228,7 +237,15 @@ trait HybridRelations
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation); return parent::belongsToMany(
$related,
$collection,
$foreignKey,
$otherKey,
$parentKey,
$relatedKey,
$relation
);
} }
// First, we'll need to determine the foreign key and "other key" for the // First, we'll need to determine the foreign key and "other key" for the
...@@ -252,7 +269,16 @@ trait HybridRelations ...@@ -252,7 +269,16 @@ trait HybridRelations
// appropriate query constraint and entirely manages the hydrations. // appropriate query constraint and entirely manages the hydrations.
$query = $instance->newQuery(); $query = $instance->newQuery();
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $relation); return new BelongsToMany(
$query,
$this,
$collection,
$foreignKey,
$otherKey,
$parentKey ?: $this->getKeyName(),
$relatedKey ?: $instance->getKeyName(),
$relation
);
} }
/** /**
......
...@@ -6,6 +6,7 @@ use Carbon\Carbon; ...@@ -6,6 +6,7 @@ use Carbon\Carbon;
use DateTime; use DateTime;
use Illuminate\Database\Eloquent\Model as BaseModel; use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Jenssegers\Mongodb\Query\Builder as QueryBuilder; use Jenssegers\Mongodb\Query\Builder as QueryBuilder;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
...@@ -46,7 +47,7 @@ abstract class Model extends BaseModel ...@@ -46,7 +47,7 @@ abstract class Model extends BaseModel
{ {
// If we don't have a value for 'id', we will use the Mongo '_id' value. // If we don't have a value for 'id', we will use the Mongo '_id' value.
// This allows us to work with models in a more sql-like way. // This allows us to work with models in a more sql-like way.
if (!$value and array_key_exists('_id', $this->attributes)) { if (!$value && array_key_exists('_id', $this->attributes)) {
$value = $this->attributes['_id']; $value = $this->attributes['_id'];
} }
...@@ -131,12 +132,12 @@ abstract class Model extends BaseModel ...@@ -131,12 +132,12 @@ abstract class Model extends BaseModel
} }
// Dot notation support. // Dot notation support.
if (str_contains($key, '.') and array_has($this->attributes, $key)) { if (Str::contains($key, '.') && Arr::has($this->attributes, $key)) {
return $this->getAttributeValue($key); return $this->getAttributeValue($key);
} }
// This checks for embedded relation support. // This checks for embedded relation support.
if (method_exists($this, $key) and !method_exists(self::class, $key)) { if (method_exists($this, $key) && !method_exists(self::class, $key)) {
return $this->getRelationValue($key); return $this->getRelationValue($key);
} }
...@@ -149,8 +150,8 @@ abstract class Model extends BaseModel ...@@ -149,8 +150,8 @@ abstract class Model extends BaseModel
protected function getAttributeFromArray($key) protected function getAttributeFromArray($key)
{ {
// Support keys in dot notation. // Support keys in dot notation.
if (str_contains($key, '.')) { if (Str::contains($key, '.')) {
return array_get($this->attributes, $key); return Arr::get($this->attributes, $key);
} }
return parent::getAttributeFromArray($key); return parent::getAttributeFromArray($key);
...@@ -162,17 +163,17 @@ abstract class Model extends BaseModel ...@@ -162,17 +163,17 @@ abstract class Model extends BaseModel
public function setAttribute($key, $value) public function setAttribute($key, $value)
{ {
// Convert _id to ObjectID. // Convert _id to ObjectID.
if ($key == '_id' and is_string($value)) { if ($key == '_id' && is_string($value)) {
$builder = $this->newBaseQueryBuilder(); $builder = $this->newBaseQueryBuilder();
$value = $builder->convertKey($value); $value = $builder->convertKey($value);
} // Support keys in dot notation. } // Support keys in dot notation.
elseif (str_contains($key, '.')) { elseif (Str::contains($key, '.')) {
if (in_array($key, $this->getDates()) && $value) { if (in_array($key, $this->getDates()) && $value) {
$value = $this->fromDateTime($value); $value = $this->fromDateTime($value);
} }
array_set($this->attributes, $key, $value); Arr::set($this->attributes, $key, $value);
return; return;
} }
...@@ -199,8 +200,8 @@ abstract class Model extends BaseModel ...@@ -199,8 +200,8 @@ abstract class Model extends BaseModel
// Convert dot-notation dates. // Convert dot-notation dates.
foreach ($this->getDates() as $key) { foreach ($this->getDates() as $key) {
if (str_contains($key, '.') and array_has($attributes, $key)) { if (Str::contains($key, '.') && Arr::has($attributes, $key)) {
array_set($attributes, $key, (string) $this->asDateTime(array_get($attributes, $key))); Arr::set($attributes, $key, (string) $this->asDateTime(Arr::get($attributes, $key)));
} }
} }
...@@ -218,20 +219,36 @@ abstract class Model extends BaseModel ...@@ -218,20 +219,36 @@ abstract class Model extends BaseModel
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function originalIsNumericallyEquivalent($key) protected function originalIsEquivalent($key, $current)
{ {
$current = $this->attributes[$key]; if (!array_key_exists($key, $this->original)) {
$original = $this->original[$key]; return false;
}
$original = $this->getOriginal($key);
if ($current === $original) {
return true;
}
if (null === $current) {
return false;
}
// Date comparison. if ($this->isDateAttribute($key)) {
if (in_array($key, $this->getDates())) {
$current = $current instanceof UTCDateTime ? $this->asDateTime($current) : $current; $current = $current instanceof UTCDateTime ? $this->asDateTime($current) : $current;
$original = $original instanceof UTCDateTime ? $this->asDateTime($original) : $original; $original = $original instanceof UTCDateTime ? $this->asDateTime($original) : $original;
return $current == $original; return $current == $original;
} }
return parent::originalIsNumericallyEquivalent($key); if ($this->hasCast($key)) {
return $this->castAttribute($key, $current) ===
$this->castAttribute($key, $original);
}
return is_numeric($current) && is_numeric($original)
&& strcmp((string) $current, (string) $original) === 0;
} }
/** /**
...@@ -242,9 +259,7 @@ abstract class Model extends BaseModel ...@@ -242,9 +259,7 @@ abstract class Model extends BaseModel
*/ */
public function drop($columns) public function drop($columns)
{ {
if (!is_array($columns)) { $columns = Arr::wrap($columns);
$columns = [$columns];
}
// Unset attributes // Unset attributes
foreach ($columns as $column) { foreach ($columns as $column) {
...@@ -263,16 +278,14 @@ abstract class Model extends BaseModel ...@@ -263,16 +278,14 @@ abstract class Model extends BaseModel
if ($parameters = func_get_args()) { if ($parameters = func_get_args()) {
$unique = false; $unique = false;
if (count($parameters) == 3) { if (count($parameters) === 3) {
list($column, $values, $unique) = $parameters; list($column, $values, $unique) = $parameters;
} else { } else {
list($column, $values) = $parameters; list($column, $values) = $parameters;
} }
// Do batch push by default. // Do batch push by default.
if (!is_array($values)) { $values = Arr::wrap($values);
$values = [$values];
}
$query = $this->setKeysForSaveQuery($this->newQuery()); $query = $this->setKeysForSaveQuery($this->newQuery());
...@@ -294,9 +307,7 @@ abstract class Model extends BaseModel ...@@ -294,9 +307,7 @@ abstract class Model extends BaseModel
public function pull($column, $values) public function pull($column, $values)
{ {
// Do batch pull by default. // Do batch pull by default.
if (!is_array($values)) { $values = Arr::wrap($values);
$values = [$values];
}
$query = $this->setKeysForSaveQuery($this->newQuery()); $query = $this->setKeysForSaveQuery($this->newQuery());
...@@ -318,11 +329,11 @@ abstract class Model extends BaseModel ...@@ -318,11 +329,11 @@ abstract class Model extends BaseModel
foreach ($values as $value) { foreach ($values as $value) {
// Don't add duplicate values when we only want unique values. // Don't add duplicate values when we only want unique values.
if ($unique and in_array($value, $current)) { if ($unique && (!is_array($current) || in_array($value, $current))) {
continue; continue;
} }
array_push($current, $value); $current[] = $value;
} }
$this->attributes[$column] = $current; $this->attributes[$column] = $current;
...@@ -340,6 +351,7 @@ abstract class Model extends BaseModel ...@@ -340,6 +351,7 @@ abstract class Model extends BaseModel
{ {
$current = $this->getAttributeFromArray($column) ?: []; $current = $this->getAttributeFromArray($column) ?: [];
if (is_array($current)) {
foreach ($values as $value) { foreach ($values as $value) {
$keys = array_keys($current, $value); $keys = array_keys($current, $value);
...@@ -347,6 +359,7 @@ abstract class Model extends BaseModel ...@@ -347,6 +359,7 @@ abstract class Model extends BaseModel
unset($current[$key]); unset($current[$key]);
} }
} }
}
$this->attributes[$column] = array_values($current); $this->attributes[$column] = array_values($current);
......
...@@ -8,6 +8,7 @@ use Illuminate\Database\Query\Builder as BaseBuilder; ...@@ -8,6 +8,7 @@ use Illuminate\Database\Query\Builder as BaseBuilder;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Jenssegers\Mongodb\Connection; use Jenssegers\Mongodb\Connection;
use MongoCollection; use MongoCollection;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
...@@ -232,7 +233,7 @@ class Builder extends BaseBuilder ...@@ -232,7 +233,7 @@ class Builder extends BaseBuilder
$wheres = $this->compileWheres(); $wheres = $this->compileWheres();
// Use MongoDB's aggregation framework when using grouping or aggregation functions. // Use MongoDB's aggregation framework when using grouping or aggregation functions.
if ($this->groups or $this->aggregate or $this->paginating) { if ($this->groups || $this->aggregate || $this->paginating) {
$group = []; $group = [];
$unwinds = []; $unwinds = [];
...@@ -286,7 +287,7 @@ class Builder extends BaseBuilder ...@@ -286,7 +287,7 @@ class Builder extends BaseBuilder
} }
// The _id field is mandatory when using grouping. // The _id field is mandatory when using grouping.
if ($group and empty($group['_id'])) { if ($group && empty($group['_id'])) {
$group['_id'] = null; $group['_id'] = null;
} }
...@@ -563,7 +564,7 @@ class Builder extends BaseBuilder ...@@ -563,7 +564,7 @@ class Builder extends BaseBuilder
public function update(array $values, array $options = []) public function update(array $values, array $options = [])
{ {
// Use $set as default operator. // Use $set as default operator.
if (!starts_with(key($values), '$')) { if (!Str::startsWith(key($values), '$')) {
$values = ['$set' => $values]; $values = ['$set' => $values];
} }
...@@ -705,7 +706,7 @@ class Builder extends BaseBuilder ...@@ -705,7 +706,7 @@ class Builder extends BaseBuilder
$operator = $unique ? '$addToSet' : '$push'; $operator = $unique ? '$addToSet' : '$push';
// Check if we are pushing multiple values. // Check if we are pushing multiple values.
$batch = (is_array($value) and array_keys($value) === range(0, count($value) - 1)); $batch = (is_array($value) && array_keys($value) === range(0, count($value) - 1));
if (is_array($column)) { if (is_array($column)) {
$query = [$operator => $column]; $query = [$operator => $column];
...@@ -728,7 +729,7 @@ class Builder extends BaseBuilder ...@@ -728,7 +729,7 @@ class Builder extends BaseBuilder
public function pull($column, $value = null) public function pull($column, $value = null)
{ {
// Check if we passed an associative array. // Check if we passed an associative array.
$batch = (is_array($value) and array_keys($value) === range(0, count($value) - 1)); $batch = (is_array($value) && array_keys($value) === range(0, count($value) - 1));
// If we are pulling multiple values, we need to use $pullAll. // If we are pulling multiple values, we need to use $pullAll.
$operator = $batch ? '$pullAll' : '$pull'; $operator = $batch ? '$pullAll' : '$pull';
...@@ -804,7 +805,7 @@ class Builder extends BaseBuilder ...@@ -804,7 +805,7 @@ class Builder extends BaseBuilder
*/ */
public function convertKey($id) public function convertKey($id)
{ {
if (is_string($id) and strlen($id) === 24 and ctype_xdigit($id)) { if (is_string($id) && strlen($id) === 24 && ctype_xdigit($id)) {
return new ObjectID($id); return new ObjectID($id);
} }
...@@ -822,7 +823,7 @@ class Builder extends BaseBuilder ...@@ -822,7 +823,7 @@ class Builder extends BaseBuilder
if (func_num_args() == 3) { if (func_num_args() == 3) {
$operator = &$params[1]; $operator = &$params[1];
if (starts_with($operator, '$')) { if (Str::startsWith($operator, '$')) {
$operator = substr($operator, 1); $operator = substr($operator, 1);
} }
} }
...@@ -866,7 +867,7 @@ class Builder extends BaseBuilder ...@@ -866,7 +867,7 @@ class Builder extends BaseBuilder
} }
// Convert id's. // Convert id's.
if (isset($where['column']) and ($where['column'] == '_id' or ends_with($where['column'], '._id'))) { if (isset($where['column']) && ($where['column'] == '_id' || Str::endsWith($where['column'], '._id'))) {
// Multiple values. // Multiple values.
if (isset($where['values'])) { if (isset($where['values'])) {
foreach ($where['values'] as &$value) { foreach ($where['values'] as &$value) {
...@@ -896,7 +897,7 @@ class Builder extends BaseBuilder ...@@ -896,7 +897,7 @@ class Builder extends BaseBuilder
// The next item in a "chain" of wheres devices the boolean of the // The next item in a "chain" of wheres devices the boolean of the
// first item. So if we see that there are multiple wheres, we will // first item. So if we see that there are multiple wheres, we will
// use the operator of the next where. // use the operator of the next where.
if ($i == 0 and count($wheres) > 1 and $where['boolean'] == 'and') { if ($i == 0 && count($wheres) > 1 && $where['boolean'] == 'and') {
$where['boolean'] = $wheres[$i + 1]['boolean']; $where['boolean'] = $wheres[$i + 1]['boolean'];
} }
...@@ -938,10 +939,10 @@ class Builder extends BaseBuilder ...@@ -938,10 +939,10 @@ class Builder extends BaseBuilder
$regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value)); $regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value));
// Convert like to regular expression. // Convert like to regular expression.
if (!starts_with($value, '%')) { if (!Str::startsWith($value, '%')) {
$regex = '^' . $regex; $regex = '^' . $regex;
} }
if (!ends_with($value, '%')) { if (!Str::endsWith($value, '%')) {
$regex = $regex . '$'; $regex = $regex . '$';
} }
...@@ -958,12 +959,12 @@ class Builder extends BaseBuilder ...@@ -958,12 +959,12 @@ class Builder extends BaseBuilder
// For inverse regexp operations, we can just use the $not operator // For inverse regexp operations, we can just use the $not operator
// and pass it a Regex instence. // and pass it a Regex instence.
if (starts_with($operator, 'not')) { if (Str::startsWith($operator, 'not')) {
$operator = 'not'; $operator = 'not';
} }
} }
if (!isset($operator) or $operator == '=') { if (!isset($operator) || $operator == '=') {
$query = [$column => $value]; $query = [$column => $value];
} elseif (array_key_exists($operator, $this->conversion)) { } elseif (array_key_exists($operator, $this->conversion)) {
$query = [$column => [$this->conversion[$operator] => $value]]; $query = [$column => [$this->conversion[$operator] => $value]];
......
...@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Builder; ...@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
use Illuminate\Support\Arr;
class BelongsToMany extends EloquentBelongsToMany class BelongsToMany extends EloquentBelongsToMany
{ {
...@@ -93,7 +94,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -93,7 +94,7 @@ class BelongsToMany extends EloquentBelongsToMany
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function create(array $attributes, array $joining = [], $touch = true) public function create(array $attributes = [], array $joining = [], $touch = true)
{ {
$instance = $this->related->newInstance($attributes); $instance = $this->related->newInstance($attributes);
...@@ -134,6 +135,8 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -134,6 +135,8 @@ class BelongsToMany extends EloquentBelongsToMany
$records = $this->formatSyncList($ids); $records = $this->formatSyncList($ids);
$current = Arr::wrap($current);
$detach = array_diff($current, array_keys($records)); $detach = array_diff($current, array_keys($records));
// We need to make sure we pass a clean array, so that it is not interpreted // We need to make sure we pass a clean array, so that it is not interpreted
...@@ -143,7 +146,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -143,7 +146,7 @@ class BelongsToMany extends EloquentBelongsToMany
// Next, we will take the differences of the currents and given IDs and detach // Next, we will take the differences of the currents and given IDs and detach
// all of the entities that exist in the "current" array but are not in the // all of the entities that exist in the "current" array but are not in the
// the array of the IDs given to the method which will complete the sync. // the array of the IDs given to the method which will complete the sync.
if ($detaching and count($detach) > 0) { if ($detaching && count($detach) > 0) {
$this->detach($detach); $this->detach($detach);
$changes['detached'] = (array) array_map(function ($v) { $changes['detached'] = (array) array_map(function ($v) {
...@@ -184,7 +187,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -184,7 +187,7 @@ class BelongsToMany extends EloquentBelongsToMany
$id = $model->getKey(); $id = $model->getKey();
// Attach the new parent id to the related model. // Attach the new parent id to the related model.
$model->push($this->foreignKey, $this->parent->getKey(), true); $model->push($this->foreignPivotKey, $this->parent->getKey(), true);
} else { } else {
if ($id instanceof Collection) { if ($id instanceof Collection) {
$id = $id->modelKeys(); $id = $id->modelKeys();
...@@ -195,7 +198,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -195,7 +198,7 @@ class BelongsToMany extends EloquentBelongsToMany
$query->whereIn($this->related->getKeyName(), (array) $id); $query->whereIn($this->related->getKeyName(), (array) $id);
// Attach the new parent id to the related model. // Attach the new parent id to the related model.
$query->push($this->foreignKey, $this->parent->getKey(), true); $query->push($this->foreignPivotKey, $this->parent->getKey(), true);
} }
// Attach the new ids to the parent model. // Attach the new ids to the parent model.
...@@ -231,7 +234,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -231,7 +234,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
// Remove the relation to the parent. // Remove the relation to the parent.
$query->pull($this->foreignKey, $this->parent->getKey()); $query->pull($this->foreignPivotKey, $this->parent->getKey());
if ($touch) { if ($touch) {
$this->touchIfTouching(); $this->touchIfTouching();
...@@ -245,7 +248,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -245,7 +248,7 @@ class BelongsToMany extends EloquentBelongsToMany
*/ */
protected function buildDictionary(Collection $results) protected function buildDictionary(Collection $results)
{ {
$foreign = $this->foreignKey; $foreign = $this->foreignPivotKey;
// First we will build a dictionary of child models keyed by the foreign key // First we will build a dictionary of child models keyed by the foreign key
// of the relation so that we will easily and quickly match them to their // of the relation so that we will easily and quickly match them to their
...@@ -286,15 +289,23 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -286,15 +289,23 @@ class BelongsToMany extends EloquentBelongsToMany
*/ */
public function getForeignKey() public function getForeignKey()
{ {
return $this->foreignKey; return $this->foreignPivotKey;
}
/**
* @inheritdoc
*/
public function getQualifiedForeignPivotKeyName()
{
return $this->foreignPivotKey;
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function getQualifiedForeignKeyName() public function getQualifiedRelatedPivotKeyName()
{ {
return $this->foreignKey; return $this->relatedPivotKey;
} }
/** /**
...@@ -324,6 +335,6 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -324,6 +335,6 @@ class BelongsToMany extends EloquentBelongsToMany
*/ */
public function getRelatedKey() public function getRelatedKey()
{ {
return property_exists($this, 'relatedKey') ? $this->relatedKey : $this->otherKey; return property_exists($this, 'relatedPivotKey') ? $this->relatedPivotKey : $this->relatedKey;
} }
} }
...@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Collection; ...@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator; use Illuminate\Pagination\Paginator;
use Illuminate\Support\Arr;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
class EmbedsMany extends EmbedsOneOrMany class EmbedsMany extends EmbedsOneOrMany
...@@ -39,7 +40,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -39,7 +40,7 @@ class EmbedsMany extends EmbedsOneOrMany
public function performInsert(Model $model) public function performInsert(Model $model)
{ {
// Generate a new key if needed. // Generate a new key if needed.
if ($model->getKeyName() == '_id' and !$model->getKey()) { if ($model->getKeyName() == '_id' && !$model->getKey()) {
$model->setAttribute('_id', new ObjectID); $model->setAttribute('_id', new ObjectID);
} }
...@@ -79,7 +80,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -79,7 +80,7 @@ class EmbedsMany extends EmbedsOneOrMany
$foreignKey = $this->getForeignKeyValue($model); $foreignKey = $this->getForeignKeyValue($model);
// Use array dot notation for better update behavior. // Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey . '.$.'); $values = Arr::dot($model->getDirty(), $this->localKey . '.$.');
// Update document in database. // Update document in database.
$result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey) $result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Jenssegers\Mongodb\Relations; namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
class EmbedsOne extends EmbedsOneOrMany class EmbedsOne extends EmbedsOneOrMany
...@@ -36,7 +37,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -36,7 +37,7 @@ class EmbedsOne extends EmbedsOneOrMany
public function performInsert(Model $model) public function performInsert(Model $model)
{ {
// Generate a new key if needed. // Generate a new key if needed.
if ($model->getKeyName() == '_id' and !$model->getKey()) { if ($model->getKeyName() == '_id' && !$model->getKey()) {
$model->setAttribute('_id', new ObjectID); $model->setAttribute('_id', new ObjectID);
} }
...@@ -71,7 +72,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -71,7 +72,7 @@ class EmbedsOne extends EmbedsOneOrMany
} }
// Use array dot notation for better update behavior. // Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey . '.'); $values = Arr::dot($model->getDirty(), $this->localKey . '.');
$result = $this->getBaseQuery()->update($values); $result = $this->getBaseQuery()->update($values);
......
...@@ -94,9 +94,11 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -94,9 +94,11 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Shorthand to get the results of the relationship. * Shorthand to get the results of the relationship.
* *
* @param array $columns
*
* @return Collection * @return Collection
*/ */
public function get() public function get($columns = ['*'])
{ {
return $this->getResults(); return $this->getResults();
} }
...@@ -280,7 +282,12 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -280,7 +282,12 @@ abstract class EmbedsOneOrMany extends Relation
return; return;
} }
$model = $this->related->newFromBuilder((array) $attributes); $connection = $this->related->getConnection();
$model = $this->related->newFromBuilder(
(array) $attributes,
$connection ? $connection->getName() : null
);
$model->setParentRelation($this); $model->setParentRelation($this);
......
...@@ -156,7 +156,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -156,7 +156,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
*/ */
public function geospatial($columns = null, $index = '2d', $options = []) public function geospatial($columns = null, $index = '2d', $options = [])
{ {
if ($index == '2d' or $index == '2dsphere') { if ($index == '2d' || $index == '2dsphere') {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
$columns = array_flip($columns); $columns = array_flip($columns);
......
...@@ -20,14 +20,7 @@ class EmbeddedRelationsTest extends TestCase ...@@ -20,14 +20,7 @@ class EmbeddedRelationsTest extends TestCase
$user = User::create(['name' => 'John Doe']); $user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']); $address = new Address(['city' => 'London']);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($address), $address);
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address);
$address = $user->addresses()->save($address); $address = $user->addresses()->save($address);
$address->unsetEventDispatcher();
$this->assertNotNull($user->addresses); $this->assertNotNull($user->addresses);
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->addresses); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->addresses);
...@@ -45,15 +38,8 @@ class EmbeddedRelationsTest extends TestCase ...@@ -45,15 +38,8 @@ class EmbeddedRelationsTest extends TestCase
$user = User::find($user->_id); $user = User::find($user->_id);
$this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all()); $this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all());
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($address), $address);
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address);
$address->city = 'New York'; $address->city = 'New York';
$user->addresses()->save($address); $user->addresses()->save($address);
$address->unsetEventDispatcher();
$this->assertEquals(2, count($user->addresses)); $this->assertEquals(2, count($user->addresses));
$this->assertEquals(2, count($user->addresses()->get())); $this->assertEquals(2, count($user->addresses()->get()));
...@@ -210,15 +196,9 @@ class EmbeddedRelationsTest extends TestCase ...@@ -210,15 +196,9 @@ class EmbeddedRelationsTest extends TestCase
$address = $user->addresses->first(); $address = $user->addresses->first();
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
$user->addresses()->destroy($address->_id); $user->addresses()->destroy($address->_id);
$this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->pluck('city')->all()); $this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->pluck('city')->all());
$address->unsetEventDispatcher();
$address = $user->addresses->first(); $address = $user->addresses->first();
$user->addresses()->destroy($address); $user->addresses()->destroy($address);
$this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all()); $this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all());
...@@ -248,17 +228,11 @@ class EmbeddedRelationsTest extends TestCase ...@@ -248,17 +228,11 @@ class EmbeddedRelationsTest extends TestCase
$address = $user->addresses->first(); $address = $user->addresses->first();
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
$address->delete(); $address->delete();
$this->assertEquals(2, $user->addresses()->count()); $this->assertEquals(2, $user->addresses()->count());
$this->assertEquals(2, $user->addresses->count()); $this->assertEquals(2, $user->addresses->count());
$address->unsetEventDispatcher();
$address = $user->addresses->first(); $address = $user->addresses->first();
$address->delete(); $address->delete();
...@@ -296,12 +270,11 @@ class EmbeddedRelationsTest extends TestCase ...@@ -296,12 +270,11 @@ class EmbeddedRelationsTest extends TestCase
$user = User::create(['name' => 'John Doe']); $user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']); $address = new Address(['city' => 'London']);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); $address::creating(function () {
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); return false;
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(false); });
$this->assertFalse($user->addresses()->save($address)); $this->assertFalse($user->addresses()->save($address));
$address->unsetEventDispatcher();
} }
public function testEmbedsManySavingEventReturnsFalse() public function testEmbedsManySavingEventReturnsFalse()
...@@ -310,11 +283,11 @@ class EmbeddedRelationsTest extends TestCase ...@@ -310,11 +283,11 @@ class EmbeddedRelationsTest extends TestCase
$address = new Address(['city' => 'Paris']); $address = new Address(['city' => 'Paris']);
$address->exists = true; $address->exists = true;
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); $address::saving(function () {
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(false); return false;
});
$this->assertFalse($user->addresses()->save($address)); $this->assertFalse($user->addresses()->save($address));
$address->unsetEventDispatcher();
} }
public function testEmbedsManyUpdatingEventReturnsFalse() public function testEmbedsManyUpdatingEventReturnsFalse()
...@@ -323,14 +296,13 @@ class EmbeddedRelationsTest extends TestCase ...@@ -323,14 +296,13 @@ class EmbeddedRelationsTest extends TestCase
$address = new Address(['city' => 'New York']); $address = new Address(['city' => 'New York']);
$user->addresses()->save($address); $user->addresses()->save($address);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); $address::updating(function () {
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); return false;
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(false); });
$address->city = 'Warsaw'; $address->city = 'Warsaw';
$this->assertFalse($user->addresses()->save($address)); $this->assertFalse($user->addresses()->save($address));
$address->unsetEventDispatcher();
} }
public function testEmbedsManyDeletingEventReturnsFalse() public function testEmbedsManyDeletingEventReturnsFalse()
...@@ -340,13 +312,12 @@ class EmbeddedRelationsTest extends TestCase ...@@ -340,13 +312,12 @@ class EmbeddedRelationsTest extends TestCase
$address = $user->addresses->first(); $address = $user->addresses->first();
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); $address::deleting(function () {
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::mustBe($address))->andReturn(false); return false;
});
$this->assertEquals(0, $user->addresses()->destroy($address)); $this->assertEquals(0, $user->addresses()->destroy($address));
$this->assertEquals(['New York'], $user->addresses->pluck('city')->all()); $this->assertEquals(['New York'], $user->addresses->pluck('city')->all());
$address->unsetEventDispatcher();
} }
public function testEmbedsManyFindOrContains() public function testEmbedsManyFindOrContains()
...@@ -443,14 +414,7 @@ class EmbeddedRelationsTest extends TestCase ...@@ -443,14 +414,7 @@ class EmbeddedRelationsTest extends TestCase
$user = User::create(['name' => 'John Doe']); $user = User::create(['name' => 'John Doe']);
$father = new User(['name' => 'Mark Doe']); $father = new User(['name' => 'Mark Doe']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father);
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father);
$father = $user->father()->save($father); $father = $user->father()->save($father);
$father->unsetEventDispatcher();
$this->assertNotNull($user->father); $this->assertNotNull($user->father);
$this->assertEquals('Mark Doe', $user->father->name); $this->assertEquals('Mark Doe', $user->father->name);
...@@ -462,29 +426,15 @@ class EmbeddedRelationsTest extends TestCase ...@@ -462,29 +426,15 @@ class EmbeddedRelationsTest extends TestCase
$raw = $father->getAttributes(); $raw = $father->getAttributes();
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']); $this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($father), $father);
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father);
$father->name = 'Tom Doe'; $father->name = 'Tom Doe';
$user->father()->save($father); $user->father()->save($father);
$father->unsetEventDispatcher();
$this->assertNotNull($user->father); $this->assertNotNull($user->father);
$this->assertEquals('Tom Doe', $user->father->name); $this->assertEquals('Tom Doe', $user->father->name);
$father = new User(['name' => 'Jim Doe']); $father = new User(['name' => 'Jim Doe']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father);
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father);
$father = $user->father()->save($father); $father = $user->father()->save($father);
$father->unsetEventDispatcher();
$this->assertNotNull($user->father); $this->assertNotNull($user->father);
$this->assertEquals('Jim Doe', $user->father->name); $this->assertEquals('Jim Doe', $user->father->name);
...@@ -495,11 +445,7 @@ class EmbeddedRelationsTest extends TestCase ...@@ -495,11 +445,7 @@ class EmbeddedRelationsTest extends TestCase
$user = User::create(['name' => 'John Doe']); $user = User::create(['name' => 'John Doe']);
$father = new User(['name' => 'Mark Doe']); $father = new User(['name' => 'Mark Doe']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->times(0)->with('eloquent.saving: ' . get_class($father), $father);
$father = $user->father()->associate($father); $father = $user->father()->associate($father);
$father->unsetEventDispatcher();
$this->assertNotNull($user->father); $this->assertNotNull($user->father);
$this->assertEquals('Mark Doe', $user->father->name); $this->assertEquals('Mark Doe', $user->father->name);
......
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Address extends Eloquent class Address extends Eloquent
{ {
protected $connection = 'mongodb';
protected static $unguarded = true; protected static $unguarded = true;
public function addresses() public function addresses()
......
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Book extends Eloquent class Book extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'books'; protected $collection = 'books';
protected static $unguarded = true; protected static $unguarded = true;
protected $primaryKey = 'title'; protected $primaryKey = 'title';
......
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Client extends Eloquent class Client extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'clients'; protected $collection = 'clients';
protected static $unguarded = true; protected static $unguarded = true;
......
...@@ -4,11 +4,12 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,11 +4,12 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Group extends Eloquent class Group extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'groups'; protected $collection = 'groups';
protected static $unguarded = true; protected static $unguarded = true;
public function users() public function users()
{ {
return $this->belongsToMany('User', null, 'groups', 'users'); return $this->belongsToMany('User', 'users', 'groups', 'users', '_id', '_id', 'users');
} }
} }
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Item extends Eloquent class Item extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'items'; protected $collection = 'items';
protected static $unguarded = true; protected static $unguarded = true;
......
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Location extends Eloquent class Location extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'locations'; protected $collection = 'locations';
protected static $unguarded = true; protected static $unguarded = true;
} }
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Photo extends Eloquent class Photo extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'photos'; protected $collection = 'photos';
protected static $unguarded = true; protected static $unguarded = true;
......
...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent; ...@@ -4,6 +4,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Role extends Eloquent class Role extends Eloquent
{ {
protected $connection = 'mongodb';
protected $collection = 'roles'; protected $collection = 'roles';
protected static $unguarded = true; protected static $unguarded = true;
......
...@@ -7,6 +7,7 @@ class Soft extends Eloquent ...@@ -7,6 +7,7 @@ class Soft extends Eloquent
{ {
use SoftDeletes; use SoftDeletes;
protected $connection = 'mongodb';
protected $collection = 'soft'; protected $collection = 'soft';
protected static $unguarded = true; protected static $unguarded = true;
protected $dates = ['deleted_at']; protected $dates = ['deleted_at'];
......
...@@ -10,6 +10,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword ...@@ -10,6 +10,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword
{ {
use Authenticatable, CanResetPassword; use Authenticatable, CanResetPassword;
protected $connection = 'mongodb';
protected $dates = ['birthday', 'entry.date']; protected $dates = ['birthday', 'entry.date'];
protected static $unguarded = true; protected static $unguarded = true;
...@@ -45,7 +46,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword ...@@ -45,7 +46,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword
public function groups() public function groups()
{ {
return $this->belongsToMany('Group', null, 'users', 'groups'); return $this->belongsToMany('Group', 'groups', 'users', 'groups', '_id', '_id', 'groups');
} }
public function photos() public function photos()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment