We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hello guys, Lets, for example, see the current case. We have the following databases:
db.define('users', { id: Number, username: String, database: String }); db.define('address', { id: Number, user_id: Number, country: String, city: String, street: String }); db.models.address.hasOne('user', db.models.users, {reverse: 'addresses', autoFetch: true});
And now when i select ALL users it generates too many sql queries like this:
(orm/mysql) SELECT `id`, `username`, `database` FROM `users` (orm/mysql) SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` = 1 (orm/mysql) SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` = 2 (orm/mysql) SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` = 3 (orm/mysql) SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` = 4 (orm/mysql) SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` = 5 (orm/mysql) SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` = 6
So basicly For every user in USERS creates a separate query from ADDRESS. Imagine if we have a milion users. This query will be soo slow.
Can this be optimized with 2 queries maybe like:
(orm/mysql) SELECT `id`, `username`, `database` FROM `users` SELECT `id`, `user_id`, `country`, `city`, `street` FROM `address` WHERE `user_id` IN (1,2,3,4,5,6)
Or maybe with 1 query like:
SELECT `id`, `username`, `database` FROM `users` LEFT JOIN `address` ON `address.user_id` = `users.id`
Thanks!
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hello guys,
Lets, for example, see the current case. We have the following databases:
And now when i select ALL users it generates too many sql queries like this:
So basicly For every user in USERS creates a separate query from ADDRESS. Imagine if we have a milion users. This query will be soo slow.
Can this be optimized with 2 queries maybe like:
Or maybe with 1 query like:
Thanks!
The text was updated successfully, but these errors were encountered: