{"record":{"id":"8988853d9f63d317","repo":"mongodb/laravel-mongodb","slug":"s-is-not-supported-for-hybrid-query-constraints","errorCode":null,"errorMessage":"%s is not supported for hybrid query constraints.","messagePattern":"(.+?) is not supported for hybrid query constraints\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Helpers/QueriesRelationships.php","lineNumber":151,"sourceCode":"\n    /**\n     * @param Relation $relation\n     *\n     * @return void\n     *\n     * @throws Exception\n     */\n    private function assertHybridRelationSupported(Relation $relation): void\n    {\n        if (\n            $relation instanceof HasOneOrMany\n            || $relation instanceof BelongsTo\n            || ($relation instanceof BelongsToMany && ! $this->isAcrossConnections($relation))\n        ) {\n            return;\n        }\n\n        throw new LogicException(class_basename($relation) . ' is not supported for hybrid query constraints.');\n    }\n\n    /**\n     * @param Builder  $hasQuery\n     * @param Relation $relation\n     *\n     * @return Collection\n     */\n    private function handleMorphToMany($hasQuery, $relation)\n    {\n        // First we select the parent models that have a relation to our related model,\n        // Then extracts related model's ids from the pivot column\n        $hasQuery->where($relation->getTable() . '.' . $relation->getMorphType(), $relation->getParent()::class);\n        $relations = $hasQuery->pluck($relation->getTable());\n        $relations = $relation->extractIds($relations->flatten(1)->toArray(), $relation->getForeignPivotKeyName());\n\n        return collect($relations);\n    }","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Helpers/QueriesRelationships.php#L133-L169","documentation":"Thrown by assertHybridRelationSupported when a relation type is used in addHybridHas/getRelatedConstraintKey on a hybrid (SQL+MongoDB) query that MongoDB cannot translate. Only HasOneOrMany, BelongsTo, and same-connection BelongsToMany are supported; e.g. a cross-connection BelongsToMany, HasManyThrough, or MorphToMany fires the guard. It names the unsupported relation class via class_basename().","triggerScenarios":"Thrown at src/Helpers/QueriesRelationships.php:151 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restructure the relationship to a supported type (HasOneOrMany, BelongsTo, or a BelongsToMany within a single connection).","Use the whereHas-style constraint only on the connection that natively supports the relation type.","Fetch related records in application code instead of adding a hybrid query constraint.","Skip the constraint for unsupported relation types with a feature-detection check on the relation class before calling addHybridHas."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0634653039468ceb0268a69192bdac64469ed043","analyzedAt":"2026-09-15T02:56:37.067Z","contentChangedAt":"2026-09-15T02:56:37.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}