Skip to content

Commit 128eb7b

Browse files
committed
Fix embedsMany related model, fixes #138
1 parent 234cfd5 commit 128eb7b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r
7979

8080
$query = $this->newQuery();
8181

82-
return new EmbedsMany($query, $this, $localKey, $foreignKey, $relation);
82+
$instance = new $related;
83+
84+
return new EmbedsMany($query, $this, $instance, $localKey, $foreignKey, $relation);
8385
}
8486

8587
/**

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ class EmbedsMany extends Relation {
3939
* @param string $relation
4040
* @return void
4141
*/
42-
public function __construct(Builder $query, Model $parent, $localKey, $foreignKey, $relation)
42+
public function __construct(Builder $query, Model $parent, Model $related, $localKey, $foreignKey, $relation)
4343
{
44+
$this->query = $query;
45+
$this->parent = $parent;
46+
$this->related = $related;
4447
$this->localKey = $localKey;
4548
$this->foreignKey = $foreignKey;
4649
$this->relation = $relation;
4750

48-
parent::__construct($query, $parent);
51+
$this->addConstraints();
4952
}
5053

5154
/**

0 commit comments

Comments
 (0)