Support for alternative loading strategies
See original GitHub issueApologies if this is documented somewhere, but I have not been able to find anything about it.
Is your feature request related to a problem? Please describe.
Not really a problem, but more of an inconvenience. It would be nice to be able to specify the Loading technique without having to drop to using the query builder.
Describe the solution you’d like
I would like to be able to specify the loading technique at the time I choose to load relationships.
Looking at the docs on Collections and seeing how relationships are currently loaded, one potential API for this could be something like:
type Strategy = 'lazy' | 'joined' | 'subquery' | 'selectin';
const author = orm.em.findOne(Author, '...', ['books', 'publishers']); // current
const author = orm.em.findOne(Author, '...', {
books: {
strategy: 'joined',
},
publishers: {
strategy: 'subquery',
},
}); // suggested
await author.books.init({
strategy: 'joined',
});
Similar to SQLAlchemy, you could even specify the load type at the relationship level:
@Entity()
export class Book {
@ManyToOne({
entity: () => Author,
strategy: 'joined',
})
author!: Author;
}
Describe alternatives you’ve considered
As mentioned above, the alternative right now seems to be to use the query builder.
Additional context
This feature seems fairly standard to ORMs. Some examples include SQLAlchemy and Objection.js
Thanks for the great project btw!
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (14 by maintainers)
Closing as finalized via #600 (and https://github.com/mikro-orm/mikro-orm/commit/3b0384e2c01813f111dcaa96aa954add9945c7e4, https://github.com/mikro-orm/mikro-orm/commit/90dc71f9dcbcb8314deae5b5c3475427a0af7c04 and https://github.com/mikro-orm/mikro-orm/commit/c25782ead50f0170b180b61f645978ffa3e658ea), feel free to try out and add more tests if you can think of something missing. Same applies to the docs, it could be much more verbose, but now I want to focus on actual development, time for improving docs will come later.
No worries, I should be able to finalize this myself.
Would be great if you could prepare some of the missing tests, and write a bit of docs, that should fit in few hours for sure :]