BUG: TripRepository.findByUserId uses invalid Drizzle ORM cross-table query #2
Labels
No labels
blocked:needs-decision
bug
chore
in-progress
security/high
security/medium
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
AuWoMe/planish#2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
TripRepository.findByUserId()insrc/repositories/trip-repository.ts(line 56-74) uses an invalid Drizzle ORM query that will cause a runtime SQL error.The Problem
The
whereclause is applied to thetripstable in Drizzle, but the second condition referencestripMembers.userId— a column from a different table. This will produce invalid SQL at runtime becausetrip_members.user_iddoes not exist on thetripstable.Impact
When a user loads their trips list (
GET /api/trips), this query runs. It will fail with a PostgreSQL error like "column trip_members.user_id does not exist" or similar, depending on how Drizzle translates it.Fix
Use a subquery or raw SQL to find trips where the user is either the owner OR a member. For example:
Fixed in commit
a5510ba: TripRepository.findByUserId used inside a where clause — Drizzle relational queries cannot reference another table without a join, so this crashed at runtime on GET /api/trips. Now resolved via subquery + inArray.Fixed in commit
a5510ba: TripRepository.findByUserId usedeq(tripMembers.userId, ...)inside adb.query.trips.findManywhere clause — Drizzle relational queries cannot reference another table without a join, so this crashed at runtime on GET /api/trips. Now resolved via subquery + inArray.