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.

Cannot eager load multiple eagers off of the same relation

See original GitHub issue

Issuehunt badges

Need to add eager loading support. This feature must have support for nested relationships to eager loading.

Currently there seems to be an issue with eager loading a relationship off the same eager loading relationship.

For example we can’t do this:

User.with_('articles.logo', 'articles.comments').get()

It doesn’t seem to fetch properly. Doing a single eager load like articles.comments.author works fine but when we use eager load another nested relation from articles such as articles.author, it overwrite the original relationship.

The code is located in the QueryBuilder classes prepare_result method. This is where the eager loading is called and registered to the model


IssueHunt Summary

Backers (Total: $0.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
josephmancusocommented, Nov 25, 2020

I completed this myself and cancelled funding for it. Thank you for everyone interested in this issue! ❤️

1reaction
josephmancusocommented, Nov 5, 2020

@Marlysson I actually think you are right. The data structure we have is not going to work. The issue is that if we do something like:

User.with('articles.comments', 'articles.author') 

It will register the articles.comments relationship on the user but then it gets overridden when we add the a articles.author relationship because its both registered to the user model.

@Marlysson So I think we need a different data structure here. I want to keep articles.comment, articles.author but I think inside we need to compile it down to:

{"articles": ['comments', 'author']}

This would also make single relationships something like this:

{"comments": ["comments"]}

but we can deal with that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eloquent Eager Load Double Relationship - laravel
I have two models, a Dance model and an Author model. The relationship is that an author can have many dances. The wrinkle...
Read more >
[Solved] Problem with eager loading multiple relationships
Hi all. I usually rely on query builder/raw sql to fetch data but it is a requirement to use eloquent's built-in methods in...
Read more >
Eager Loading - Sequelize
In Sequelize, eager loading is mainly done by using the include option on a model finder query (such as findOne , findAll ,...
Read more >
Eager loading multiple has_many :through relations ... - GitHub
Incorrect data is returned from has_many :through relations when two or more are eager loaded with the same :source . In the example...
Read more >
How to Eager load when there's Lazy loading involved - Medium
As we can see in the Department class the employees are mapped using a list in a one to many bi-directional mapping. This...
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