laravel / nova-issues

556 stars 34 forks source link

MySql Query error in unique belongsToMany Fields #5631

Closed gepopp closed 1 year ago

gepopp commented 1 year ago

Description:

Not sure if this is really Nova issue or if this belongs to eloquent, ive got a BelongsToMany Relation between a PressAgency Model and the User Model setup like so:

BelongsToMany::make( 'Nutzer', 'users', 'App\Nova\User' )
                         ->fields( function ( $request, $relatedModel ) {
                             return [
                                 Text::make( 'Role' ),
                                 Boolean::make( 'owner' )->default( false ),
                             ];
                         } )->searchable()
                         ->dontReorderAttachables()
                         ->allowDuplicateRelations(),

If i remove the "allowDuplicateRelations" function it throws a mySql error when searching for users, the query looks like:

select * fromuserswhere not exists (selectpress_agency_idfrompressagency_userwherepressagency_user.press_agency_id= 1 and press_agencies.id =pressagency_user.press_agency_id) andusers.idin (1, 3728, 3222, 2576) order byupdated_atasc

and the error:

1054 - Unknown Tabel Column 'press_agencies.id' in where clause

As far as i found out in mySql 8 you cannot reference outer tables in a subquery?

Any Idea how to solve this?

Detailed steps to reproduce the issue on a fresh Nova installation:

gepopp commented 1 year ago

i had an err in the relation setup....