Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] In case of disabled lazy load eager load relation query on update #5520

Open
gaborfarkas0211 opened this issue May 15, 2024 · 1 comment
Labels

Comments

@gaborfarkas0211
Copy link

gaborfarkas0211 commented May 15, 2024

Bug report

What I did

Lazy load is disabled in my project. I have a repeatable field using a hasMany relation on create and update. In the setup, I eager load the required relations for operations. I created an entry with the hasMany relation using the repeatable field. When I tried to update, the edit action gave me an error: Attempted to lazy load [relation] on model [model] but lazy loading is disabled.

What I expected to happen

The relations are loaded and the repeatable field is filled on update.

What happened

I have got the $entry property on CrudPanel without relations. The UpdateOperation edit's action checks the access to the given model. That means the CrudPanel's Access trait will set the $entry property using 'getModelWithCrudPanelQuery' query. After that the $entry property is set and the custom query will not used.

What I've already tried to fix it

There is no way for me to fix it unless I override the UpdateOperation's edit action in my project.

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?

Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

8.3.4

LARAVEL VERSION:

11.7.0.0

BACKPACK PACKAGE VERSIONS:

backpack/crud: 6.7.12
backpack/pro: 2.2.0

@pxpm
Copy link
Contributor

pxpm commented May 20, 2024

Hey @gaborfarkas0211 thanks for the report.

It's an issue that we are aware, unfortunately it's a BC to introduce and we missed the opportunity to do it in v6 sadly :(

Please fix it on your side for the moment, an easy way would be to create a copy of the update operation trait to your app and call it UpdateEagerLoadOperation, do the changes you need there. That way you don't polute your crud controller with overrides, and next version when we fix it, you just search and replace your custom operation for the backpack fixed one and you are golden.

Let me know if that helps.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

2 participants