The /jobs page is throwing this error:
Failed to fetch jobs: Could not find a relationship between 'jobs' and 'user_profiles' in the schema cache
In src/app/(dashboard)/jobs/actions.ts, the listJobs function (line ~69) is trying to use a foreign key relationship that doesn't exist:
technician:user_profiles!jobs_technician_id_fkey(
id,
display_name
)The database schema shows:
jobs.technician_id→ referencesauth.users.id(NOT user_profiles)user_profiles.user_id→ referencesauth.users.id- There is NO direct foreign key between
jobsanduser_profiles
Use the two-step query pattern that's already working in src/app/(dashboard)/schedule/actions.ts (see the listJobEvents function around line 132).
In src/app/(dashboard)/jobs/actions.ts (starting around line 69):
Remove the incorrect join:
technician:user_profiles!jobs_technician_id_fkey(
id,
display_name
)Replace with two-step query pattern:
- Query jobs with customers only (remove technician join)
- Collect unique technician IDs from results
- Separately query user_profiles for those IDs
- Create a technicianMap
- Merge technician data back into the job rows
Reference the working pattern from schedule/actions.ts lines 132-196 - copy that exact pattern.
In the same file, around line 314, the getJob function has the same issue:
technician:user_profiles!jobs_technician_id_fkey(
id,
display_name,
phone_e164,
zone
)Apply the same two-step pattern here.
Search the entire actions.ts file for any other occurrences of user_profiles!jobs_technician_id_fkey and fix them using the same pattern.
The response types already expect the technician structure, so those should be fine. Just ensure the merged data matches the expected shape:
technician?: {
id: string
display_name?: string | null
}After the fix:
- Jobs page loads without errors
- Customer names display correctly
- Technician names appear for assigned jobs
- All filters and pagination work
- The query follows the proven pattern from schedule/actions.ts
Look at src/app/(dashboard)/schedule/actions.ts line 132-196 for the exact working implementation of this pattern. Copy that approach.