Skip to content

Commit 9df75b7

Browse files
authored
Merge pull request #1487 from benargo/wherehas
Fix #1293: Exception: BelongsToMany Is Not supported for hybrid query constraints! #1324
2 parents 9e4786c + 6d4888a commit 9df75b7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
78
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
89
use Jenssegers\Mongodb\Eloquent\Model;
910

@@ -112,7 +113,11 @@ protected function getRelatedConstraintKey($relation)
112113
return $relation->getForeignKey();
113114
}
114115

115-
throw new \Exception(class_basename($relation) . ' Is Not supported for hybrid query constraints!');
116+
if ($relation instanceof BelongsToMany && ! $this->isAcrossConnections($relation)) {
117+
return $this->model->getKeyName();
118+
}
119+
120+
throw new \Exception(class_basename($relation) . ' is not supported for hybrid query constraints.');
116121
}
117122

118123
/**

0 commit comments

Comments
 (0)