You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
awaitthis.userRepository.find({},{populate: ['roles'],strategy: LoadStrategy.JOINED,limit: 1,});/* Output:select `e0`.`id`, `r1`.`id` as `r1__id`from `user` as `e0` left join `user_roles` as `e2` on `e0`.`id` = `e2`.`user_id` left join `role` as `r1` on `e2`.`role_id` = `r1`.`id` limit 1*/
With fields will produce 2 queries
awaitthis.userRepository.find({},{populate: ['roles'],fields: ['id','roles.id'],// id = users.idstrategy: LoadStrategy.JOINED,limit: 1,});/* Outputselect `e0`.`id` from `user` as `e0` limit 1 [took 5 ms]select `e0`.`id`, `e1`.`role_id` as `fk__role_id` from `role` as `e0` left join `user_roles` as `e1` on `e0`.`id` = `e1`.`role_id` where `e1`.`user_id` in (7) limit 1 [took 6 ms]*/
Expected behavior
Expected to produce 1 SQL whenever fields property is provided or not.
Additional context
N/A
Versions
Dependency
Version
node
14.15.0
typescript
4.2.4
mikro-orm
4.5.3
@mikro-orm/mysql
4.5.3
@mikro-orm/nestjs
4.2.0
The text was updated successfully, but these errors were encountered:
Yes, this combination is currently not implemented. Btw you can't use limit here if you want to use joined strategy and load to-many relation that way. You'd have to use QueryFlag.PAGINATE if you really need to restrict the SQL query limit, otherwise it will never select more than one entity at a level (so you would always end up with one role at most).
Yes, this combination is currently not implemented. Btw you can't use limit here if you want to use joined strategy and load to-many relation that way. You'd have to use QueryFlag.PAGINATE if you really need to restrict the SQL query limit, otherwise it will never select more than one entity at a level (so you would always end up with one role at most).
Okay and Thanks for the recommendation.
BTW, MikroORM is great and we are using it to develop our product.
Describe the bug
Adding fields in find() will produce extra SQL even LoadStrategy is JOINED.
Is it the expected behaviour?
Stack trace
N/A
To Reproduce
FYR: Initialise repo
Without fields will produce 1 query
With fields will produce 2 queries
Expected behavior
Expected to produce 1 SQL whenever fields property is provided or not.
Additional context
N/A
Versions
The text was updated successfully, but these errors were encountered: