Skip to content

fix(filament): qualify hosts.id in HostsRelationManager (ambiguous column) — AID-600 - #197

Merged
abkrim merged 1 commit into
mainfrom
abdelkarim/aid-600-hosts-relationmanager-ambiguous-id
Jul 20, 2026
Merged

fix(filament): qualify hosts.id in HostsRelationManager (ambiguous column) — AID-600#197
abkrim merged 1 commit into
mainfrom
abdelkarim/aid-600-hosts-relationmanager-ambiguous-id

Conversation

@abkrim

@abkrim abkrim commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes AID-600.

Problem

The Acceso a Servidores relation manager on UserResource crashed with SQLSTATE[HY000]: ambiguous column name: id when 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

HostsRelationManager used whereNotIn('id', $assignedHostIds) unqualified in three places (form options + two recordSelectOptionsQuery). The BelongsToMany base query joins user_host_permissions, which also has an id column, so the reference is ambiguous. It only fired when $assignedHostIds was non-empty — that is why it slipped through: a user with zero hosts never emitted the clause.

Fix

Qualify the column as hosts.id in the three call sites.

Test

Added a Livewire regression test that drives the full attach flow (callTableAction selecting a host). Verified by reverted perturbation: it fails with the exact production QueryException before the fix and passes after.

composer check-full green 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.

…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>
@abkrim
abkrim merged commit 3ed1de4 into main Jul 20, 2026
2 checks passed
@abkrim
abkrim deleted the abdelkarim/aid-600-hosts-relationmanager-ambiguous-id branch July 20, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant