laravel / nova-issues

554 stars 35 forks source link

BelongsToMany has many duplicate queries on detail page #6479

Open niekdemelker opened 1 month ago

niekdemelker commented 1 month ago

Description:

When using an BelongsToMany field, this will show all related models on the Details page. This request to fetch all relation records however calls the DB many times to fetch the ViaResource model. Sometimes over 20 times in one request (Strange enough Model::preventLazyLoading(! app()->isProduction()) doesn't block this behaviour.).

The logging states this call is done repeatedly from 'Http/Requests/InteractsWithRelatedResources.php:72' and one time from 'Http/Requests/QueriesResources.php:38'.

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

crynobone commented 1 month ago

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

niekdemelker commented 1 month ago

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone I already did that. the steps to reproduce take into account you use the provided repo. Se https://github.com/niekdemelker/issue-6479

niekdemelker commented 1 month ago

Do you still require more info? If you need more information on some parts please tell so I can Elaborate