1
1
<?php namespace Jenssegers \Mongodb \Relations ;
2
2
3
3
use Illuminate \Database \Eloquent \Builder ;
4
- use Illuminate \Database \Eloquent \Collection as BaseCollection ;
4
+ use Illuminate \Database \Eloquent \Collection ;
5
5
use Illuminate \Database \Eloquent \Model ;
6
6
use Illuminate \Database \Eloquent \Relations \Relation ;
7
- use Jenssegers \Mongodb \Eloquent \Collection ;
8
7
9
8
abstract class EmbedsOneOrMany extends Relation {
10
9
@@ -104,7 +103,7 @@ public function initRelation(array $models, $relation)
104
103
* @param string $relation
105
104
* @return array
106
105
*/
107
- public function match (array $ models , BaseCollection $ results , $ relation )
106
+ public function match (array $ models , Collection $ results , $ relation )
108
107
{
109
108
foreach ($ models as $ model )
110
109
{
@@ -121,7 +120,7 @@ public function match(array $models, BaseCollection $results, $relation)
121
120
/**
122
121
* Shorthand to get the results of the relationship.
123
122
*
124
- * @return \Jenssegers\Mongodb \Eloquent\Collection
123
+ * @return \Illuminate\Database \Eloquent\Collection
125
124
*/
126
125
public function get ()
127
126
{
@@ -212,7 +211,7 @@ public function createMany(array $records)
212
211
*/
213
212
protected function getIdsArrayFrom ($ ids )
214
213
{
215
- if ($ ids instanceof Collection)
214
+ if ($ ids instanceof \ Illuminate \ Support \ Collection)
216
215
{
217
216
$ ids = $ ids ->all ();
218
217
}
@@ -237,7 +236,9 @@ protected function getEmbedded()
237
236
// Get raw attributes to skip relations and accessors.
238
237
$ attributes = $ this ->parent ->getAttributes ();
239
238
240
- return isset ($ attributes [$ this ->localKey ]) ? $ attributes [$ this ->localKey ] : null ;
239
+ $ embedded = isset ($ attributes [$ this ->localKey ]) ? (array ) $ attributes [$ this ->localKey ] : [];
240
+
241
+ return $ embedded ;
241
242
}
242
243
243
244
/**
@@ -248,6 +249,7 @@ protected function getEmbedded()
248
249
*/
249
250
protected function setEmbedded ($ records )
250
251
{
252
+ // Assign models to parent attributes array.
251
253
$ attributes = $ this ->parent ->getAttributes ();
252
254
253
255
$ attributes [$ this ->localKey ] = $ records ;
@@ -256,7 +258,7 @@ protected function setEmbedded($records)
256
258
$ this ->parent ->setRawAttributes ($ attributes );
257
259
258
260
// 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 ());
260
262
}
261
263
262
264
/**
@@ -280,7 +282,7 @@ protected function getForeignKeyValue($id)
280
282
* Convert an array of records to a Collection.
281
283
*
282
284
* @param array $records
283
- * @return \Jenssegers\Mongodb \Eloquent\Collection
285
+ * @return \Illuminate\Database \Eloquent\Collection
284
286
*/
285
287
protected function toCollection (array $ records = [])
286
288
{
0 commit comments