-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Remove force loading model relationships #2412
Conversation
- $model->load('permissions');
+ $model->unsetRelation('permissions'); One thing I want to research is what the issues were when we specifically added the |
Actually it is not a bug/issue, it is a performance improvement, it is not necessary to load the relation immediately, it is enough to remove it, if there is any check after that the relation will be reloaded, otherwise this sql and memory usage are avoided Look at the tests, the sql count is less on
Ok, after sync, detach, the relations may be preloaded, if so, the new changes are not accessible, so use @drbyte here efab130, laravel-permission/releases/tag/2.25.0 |
Right. So it seems our existing |
+ $this->testUser->loadMissing('roles.permissions', 'permissions'); // load relations I'm concerned that requiring this in the Cache tests may indicate ripple-effect problems. |
Those tests are supposed to check that no unnecessary calls are made to the db after the relations have been loaded. |
No. I'm just letting you know my thoughts as I look at the PR. I think this should be fine. |
Alternative to #2410
In some scenarios it is not necessary to load the relationships, and they are loaded later when they are required, this would allow less sqls to be executed in the mentioned scenarios
Example: batch user creation and assignment