question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for alternative loading strategies

See original GitHub issue

Apologies 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:closed
  • Created 3 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
B4nancommented, Jun 7, 2020

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.

1reaction
B4nancommented, May 24, 2020

No worries, I should be able to finalize this myself.

If there are any smaller pieces of work (<5-6 hours) that can be done in isolation or with minimal interaction (thinking about rebases, merge conflicts, etc) feel free to point me to them.

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 :]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Efficiently load third-party JavaScript - web.dev
Learn how to avoid the common pitfalls of using third-party scripts to improve load times and user experience.
Read more >
9 Quick Ways to Improve Page Loading Speed - HubSpot Blog
Tired of the long wait? Discover simple tactics you can implement that will reduce the load time on your webpages.
Read more >
Loading Alternative Resources - SAP Help Portal
You can use this function to load the alternative resources for operations or orders from the production process models onto the detailed scheduling ......
Read more >
Load Balancing Algorithms, Types and Techniques - Kemp
LoadMaster supports a rich set of techniques ranging from simple round-robin load balancing to adaptive load balancing that responds to status information ...
Read more >
6 Scaffolding Strategies to Use With Your Students - Edutopia
Support every student by breaking learning up into chunks and providing a concrete ... Sometimes referred to as front-loading vocabulary, this is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found