fix(filament): qualify hosts.id in HostsRelationManager (ambiguous column) — AID-600 - #197
Merged
abkrim merged 1 commit intoJul 20, 2026
Conversation
…guous column (AID-600)
The "Asignar Servidor" attach action on UserResource crashed with
"SQLSTATE[HY000]: ambiguous column name: id" whenever the target user
already had at least one host assigned. The BelongsToMany base query joins
user_host_permissions (which also has an id column), so the unqualified
whereNotIn('id', ...) used to exclude already-assigned hosts was ambiguous.
Qualify it as hosts.id in the three call sites.
Regression covered by a Livewire test that drives the full attach flow and
fails with the exact production error before the fix.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes AID-600.
Problem
The Acceso a Servidores relation manager on
UserResourcecrashed withSQLSTATE[HY000]: ambiguous column name: idwhen opening Asignar Servidor for a user that already had at least one host assigned. Filament rendered the generic "Error al cargar la página".Root cause
HostsRelationManagerusedwhereNotIn('id', $assignedHostIds)unqualified in three places (form options + tworecordSelectOptionsQuery). TheBelongsToManybase query joinsuser_host_permissions, which also has anidcolumn, so the reference is ambiguous. It only fired when$assignedHostIdswas non-empty — that is why it slipped through: a user with zero hosts never emitted the clause.Fix
Qualify the column as
hosts.idin the three call sites.Test
Added a Livewire regression test that drives the full attach flow (
callTableActionselecting a host). Verified by reverted perturbation: it fails with the exact productionQueryExceptionbefore the fix and passes after.composer check-fullgreen locally (tests + Pint + PHPStan, coverage 89.8%).Ops note
Production (argos01) was already unblocked in place for the incident (host 15 / srv122 attached to user 39 via a direct pivot insert). This PR fixes the UI so it does not recur; no data migration needed.