-
Notifications
You must be signed in to change notification settings - Fork 132
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
fix: UserModel::assignIdentities() always produces a DB query #806
fix: UserModel::assignIdentities() always produces a DB query #806
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalsn thank you!
Am I correct in assuming that this PR prevents queries to retrieve unnecessary Identities from being executed? |
The code looks good. |
Co-authored-by: kenjis <[email protected]>
There was never a problem with the incorrect result per se. The problem here was that we were producing n+1 queries for code like this: $users = model(UserModel::class)->withIdentities()->findAll();
foreach ($users as $user) {
$user->email;
} That would be just fine, but since we use |
Thanks All! |
In the
UserModel
- when we usewithIdentities()
method the query is produced properly.The problem occurs in the
assignIdentities()
method, when we're trying to assign identities to the users.We're working with the
User
entity, and there is a line:It will call
getIdentities()
method which will produce a query to the DB, since there are no identities assigned yet.This PR solves this problem.