Skip to content

Commit 7438f7b

Browse files
committed
Fixes #736
1 parent 30bb30c commit 7438f7b

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77

88
class EmbedsMany extends EmbedsOneOrMany
99
{
10+
/**
11+
* Initialize the relation on a set of models.
12+
*
13+
* @param array $models
14+
* @param string $relation
15+
*/
16+
public function initRelation(array $models, $relation)
17+
{
18+
foreach ($models as $model) {
19+
$model->setRelation($relation, $this->related->newCollection());
20+
}
21+
22+
return $models;
23+
}
24+
1025
/**
1126
* Get the results of the relationship.
1227
*

src/Jenssegers/Mongodb/Relations/EmbedsOne.php

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66
class EmbedsOne extends EmbedsOneOrMany
77
{
8+
/**
9+
* Initialize the relation on a set of models.
10+
*
11+
* @param array $models
12+
* @param string $relation
13+
*/
14+
public function initRelation(array $models, $relation)
15+
{
16+
foreach ($models as $model) {
17+
$model->setRelation($relation, null);
18+
}
19+
20+
return $models;
21+
}
22+
823
/**
924
* Get the results of the relationship.
1025
*

src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php

-17
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,6 @@ public function addEagerConstraints(array $models)
7575
// There are no eager loading constraints.
7676
}
7777

78-
/**
79-
* Initialize the relation on a set of models.
80-
*
81-
* @param array $models
82-
* @param string $relation
83-
*/
84-
public function initRelation(array $models, $relation)
85-
{
86-
foreach ($models as $model) {
87-
$model->setParentRelation($this);
88-
89-
$model->setRelation($relation, $this->related->newCollection());
90-
}
91-
92-
return $models;
93-
}
94-
9578
/**
9679
* Match the eagerly loaded results to their parents.
9780
*

0 commit comments

Comments
 (0)