Cannot eager load multiple eagers off of the same relation
See original GitHub issueNeed 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
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (14 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I completed this myself and cancelled funding for it. Thank you for everyone interested in this issue! ❤️
@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:
It will register the
articles.commentsrelationship on the user but then it gets overridden when we add the aarticles.authorrelationship 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.authorbut I think inside we need to compile it down to:This would also make single relationships something like this:
but we can deal with that.