Skip to content

Commit 5b42dcc

Browse files
HybridRelations::morphTo() needs to respect $ownerKey
Actually is forced to use `_id`
1 parent 2d76d22 commit 5b42dcc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Jenssegers/Mongodb/Eloquent/HybridRelations.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
184184
// there are multiple types in the morph and we can't use single queries.
185185
if (($class = $this->$type) === null) {
186186
return new MorphTo(
187-
$this->newQuery(), $this, $id, null, $type, $name
187+
$this->newQuery(), $this, $id, $ownerKey, $type, $name
188188
);
189189
}
190190

@@ -195,8 +195,10 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
195195

196196
$instance = new $class;
197197

198+
$ownerKey = $ownerKey ?? $instance->getKeyName();
199+
198200
return new MorphTo(
199-
$instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name
201+
$instance->newQuery(), $this, $id, $ownerKey, $type, $name
200202
);
201203
}
202204

0 commit comments

Comments
 (0)