orm: Cannot eager load multiple eagers off of the same relation

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (14 by maintainers)

Most upvoted comments

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:

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.