F
Filament5mo ago
Mikail

'id' column with join

I'm having a Column 'id' in where clause is ambiguous when i use join to filter the query: public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->join('enrollments', 'users.id', '=', 'enrollments.user_id') ->leftJoin('applications', 'users.id', '=', 'applications.user_id') ->select( 'users.*', 'enrollments.section_id', 'enrollments.school_class_id', 'enrollments.status', 'applications.application_id', 'applications.class_of_entry_id', 'applications.screening_mark', 'applications.screening_status' ) ->where('users.role_id', Role::STUDENT); } The database doesn't know which column to choose the 'id' from. This only gives error in edit and view $operation. Any help to fix this??
4 Replies
awcodes
awcodes5mo ago
Can you be more specific? There’s 7 different ids in the code you shared and most likely there’s a relationship that is off.
Mikail
MikailOP5mo ago
The resource is 'users'. But the database doesn't know which id to use in edit $operation for the user resource since it's joined to two other models. Hope it's clear now... ?
Dennis Koch
Dennis Koch5mo ago
What's the actual query? Where does the id come from. I think we usually use the fully qualified key for db queries
Mikail
MikailOP5mo ago
For the getEloquentQuery(): above i get SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous error when i want to edit a row. the SQL is AND id = 892 but i think it's expecting users.id due to join tables
Want results from more Discord servers?
Add your server