Skip to content

Commit 17b8028

Browse files
committed
Fixes for Laravel 5.2
1 parent 4cdb4fb commit 17b8028

File tree

11 files changed

+78
-315
lines changed

11 files changed

+78
-315
lines changed

src/Jenssegers/Mongodb/Eloquent/Collection.php

Lines changed: 0 additions & 248 deletions
This file was deleted.

src/Jenssegers/Mongodb/Model.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ public function setAttribute($key, $value)
322322
parent::setAttribute($key, $value);
323323
}
324324

325+
/**
326+
* Get the casts array.
327+
*
328+
* @return array
329+
*/
330+
public function getCasts()
331+
{
332+
return $this->casts;
333+
}
334+
325335
/**
326336
* Convert the model's attributes to an array.
327337
*
@@ -372,6 +382,7 @@ protected function originalIsNumericallyEquivalent($key)
372382
{
373383
$current = $current instanceof MongoDate ? $this->asDateTime($current) : $current;
374384
$original = $original instanceof MongoDate ? $this->asDateTime($original) : $original;
385+
375386
return $current == $original;
376387
}
377388

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Builder extends BaseBuilder {
8585
*/
8686
public function __construct(Connection $connection, Processor $processor)
8787
{
88+
$this->grammar = new Grammar;
8889
$this->connection = $connection;
8990
$this->processor = $processor;
9091
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php namespace Jenssegers\Mongodb\Query;
2+
3+
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
4+
5+
class Grammar extends BaseGrammar
6+
{
7+
8+
}

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class EmbedsMany extends EmbedsOneOrMany {
1010
/**
1111
* Get the results of the relationship.
1212
*
13-
* @return \Jenssegers\Mongodb\Eloquent\Collection
13+
* @return \Illuminate\Database\Eloquent\Collection
1414
*/
1515
public function getResults()
1616
{
@@ -321,7 +321,7 @@ protected function setEmbedded($models)
321321
public function __call($method, $parameters)
322322
{
323323
// Collection methods
324-
if (method_exists('Jenssegers\Mongodb\Eloquent\Collection', $method))
324+
if (method_exists('Illuminate\Database\Eloquent\Collection', $method))
325325
{
326326
return call_user_func_array([$this->getResults(), $method], $parameters);
327327
}

src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php namespace Jenssegers\Mongodb\Relations;
22

33
use Illuminate\Database\Eloquent\Builder;
4-
use Illuminate\Database\Eloquent\Collection as BaseCollection;
4+
use Illuminate\Database\Eloquent\Collection;
55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Eloquent\Relations\Relation;
7-
use Jenssegers\Mongodb\Eloquent\Collection;
87

98
abstract class EmbedsOneOrMany extends Relation {
109

@@ -104,7 +103,7 @@ public function initRelation(array $models, $relation)
104103
* @param string $relation
105104
* @return array
106105
*/
107-
public function match(array $models, BaseCollection $results, $relation)
106+
public function match(array $models, Collection $results, $relation)
108107
{
109108
foreach ($models as $model)
110109
{
@@ -121,7 +120,7 @@ public function match(array $models, BaseCollection $results, $relation)
121120
/**
122121
* Shorthand to get the results of the relationship.
123122
*
124-
* @return \Jenssegers\Mongodb\Eloquent\Collection
123+
* @return \Illuminate\Database\Eloquent\Collection
125124
*/
126125
public function get()
127126
{
@@ -212,7 +211,7 @@ public function createMany(array $records)
212211
*/
213212
protected function getIdsArrayFrom($ids)
214213
{
215-
if ($ids instanceof Collection)
214+
if ($ids instanceof \Illuminate\Support\Collection)
216215
{
217216
$ids = $ids->all();
218217
}
@@ -237,7 +236,9 @@ protected function getEmbedded()
237236
// Get raw attributes to skip relations and accessors.
238237
$attributes = $this->parent->getAttributes();
239238

240-
return isset($attributes[$this->localKey]) ? $attributes[$this->localKey] : null;
239+
$embedded = isset($attributes[$this->localKey]) ? (array) $attributes[$this->localKey] : [];
240+
241+
return $embedded;
241242
}
242243

243244
/**
@@ -248,6 +249,7 @@ protected function getEmbedded()
248249
*/
249250
protected function setEmbedded($records)
250251
{
252+
// Assign models to parent attributes array.
251253
$attributes = $this->parent->getAttributes();
252254

253255
$attributes[$this->localKey] = $records;
@@ -256,7 +258,7 @@ protected function setEmbedded($records)
256258
$this->parent->setRawAttributes($attributes);
257259

258260
// Set the relation on the parent.
259-
return $this->parent->setRelation($this->relation, $this->getResults());
261+
return $this->parent->setRelation($this->relation, $records === null ? null : $this->getResults());
260262
}
261263

262264
/**
@@ -280,7 +282,7 @@ protected function getForeignKeyValue($id)
280282
* Convert an array of records to a Collection.
281283
*
282284
* @param array $records
283-
* @return \Jenssegers\Mongodb\Eloquent\Collection
285+
* @return \Illuminate\Database\Eloquent\Collection
284286
*/
285287
protected function toCollection(array $records = [])
286288
{

0 commit comments

Comments
 (0)