{"record":{"id":"be34b5e399b1c095","repo":"filamentphp/filament","slug":"the-relationship-relationshipname-does-not-ex","errorCode":null,"errorMessage":"The relationship [{$relationshipName}] does not exist on the model [{$this->getModel()}].","messagePattern":"The relationship \\[(.+?)\\] does not exist on the model \\[(.+?)\\]\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"packages/forms/src/Components/ModalTableSelect.php","lineNumber":762,"sourceCode":"        foreach (explode('.', $relationshipName) as $nestedRelationshipName) {\n            if ($record->hasAttribute($nestedRelationshipName)) {\n                $relationship = null;\n\n                break;\n            }\n\n            if (! $record->isRelation($nestedRelationshipName)) {\n                $relationship = null;\n\n                break;\n            }\n\n            $relationship = $record->{$nestedRelationshipName}();\n            $record = $relationship->getRelated();\n        }\n\n        if (! $relationship) {\n            throw new LogicException(\"The relationship [{$relationshipName}] does not exist on the model [{$this->getModel()}].\");\n        }\n\n        return $relationship;\n    }\n\n    public function getRelationshipName(): ?string\n    {\n        return $this->evaluate($this->relationship);\n    }\n\n    public function getSelectedRecord(): ?Model\n    {\n        if ($this->cachedSelectedRecord) {\n            return $this->cachedSelectedRecord;\n        }\n\n        if (blank($this->getState())) {\n            return null;","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/filamentphp/filament/blob/53483fa9340e4ec637985fe454ebb58afb92ea24/packages/forms/src/Components/ModalTableSelect.php#L744-L780","documentation":"`ModalTableSelect::getRelationship()` supports dot-chained names by walking each segment: every hop must not be a plain attribute and must pass `isRelation()` on the current record's model. If any hop fails, `$relationship` stays null and a LogicException naming the full chain is thrown instead of returning a broken query.","triggerScenarios":"`->relationship('team.users')` where the model has no `team()` method (or any intermediate hop resolves to a non-relation); also a first-segment typo like `->relationship('usr')`.","commonSituations":"Selecting records from a related table through a chain, where an intermediate `hasMany`/`belongsTo` was renamed or never defined, or where a segment is actually a cast attribute.","solutions":["Define every missing hop on the model: `public function team(): BelongsTo { ... }` and `public function users(): HasMany { ... }`.","Check each segment with `isRelation()` on the corresponding model to pinpoint the failing hop.","Simplify to a single existing relationship or use `->options()` with a custom query if the chain does not exist."],"exampleFix":"// before — `Project` has no `members()` relation\nModalTableSelect::make('user_id')\n    ->relationship('members.id', 'name'),\n\n// after\nModalTableSelect::make('user_id')\n    ->relationship('team.users', 'name'), // both hops exist on the models","handlingStrategy":"validation","validationCode":"// Verify each hop of a dot-chained relationship before rendering\n$record = $modelClass::newInstance();\n\nforeach (explode('.', $relationshipName) as $segment) {\n    if ($record->hasAttribute($segment) || (! $record->isRelation($segment))) {\n        throw new InvalidArgumentException(\n            \"Segment [{$segment}] of [{$relationshipName}] is not a relation on [\" . $record::class . '].'\n        );\n    }\n\n    $record = $record->{$segment}()->getRelated();\n}","typeGuard":"function modelChainHasRelations(string $modelClass, string $dottedName): bool\n{\n    $record = $modelClass::newInstance();\n\n    foreach (explode('.', $dottedName) as $segment) {\n        if ($record->hasAttribute($segment) || (! $record->isRelation($segment))) {\n            return false;\n        }\n\n        $record = $record->{$segment}()->getRelated();\n    }\n\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Add every hop of the chain to the model, and validate chains in a schema lint.","Prefer short chains; intermediate models change and break long ones.","Test the field renders against the real model in CI."],"tags":["filament","forms","eloquent","relationships","modal-table-select"],"backgroundTag":"missing-eloquent-relationship","analyzedSha":"53483fa9340e4ec637985fe454ebb58afb92ea24","analyzedAt":"2026-08-17T02:06:23.049Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}