nested joins: regression since v4.6.0?
See original GitHub issueThere seems that a regression was introduced since v4.6.0
Here is my controller:
@Crud(
[...]
query: {
join: {
posts: {}
posts.comments: {}
posts.comments.user: {}
}
})
export class PostsController {
And HTTP GET:
http://localhost:3000/posts?join=posts&join=posts.comments&join=posts.comments.user
Error:
Error: Relation with property path comments.user in entity was not found.
It works with v4.5.0
After some debugging, the TypeORM relation path used for user entity is: In v4.5.0: comments.user in v4.6.0: posts.comments.user
Here is the line where the error is thrown: function setJoins in packages/crud-typeorm/src/typeorm-crud.service.ts
builder[relationType](allowedRelation.path, alias);
I don’t know if it can be fixed easily or not, though.
Thanks for your feedback!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Rails Nested Joins Activerecord with conditions - sql
Looks like you don't need nested joins here. Try to use something like. Event.joins(:store).where(stores: {retailer_id: 2}).
Read more >What to do AFTER nested cross-validation?
I'd go for lambda.1se . Question #6 [and #4]: In the end, I just want one LASSO logistic regression model, with one unique...
Read more >How to avoid BroadcastNestedJoin in Spark | by Vikas Singh
Based on the aforementioned parameters, Spark selects one of the join strategy listed below: Broadcast Hash Join; Shuffle hash join; Shuffle ...
Read more >Lecture 9: Joining multiple datasets
3.1 Overview of mutating joins; 3.2 Practical example; 3.3 Inner joins ... cbirthm <dbl> 12, 10, 3, 5, 1, 7, 3, 10, 9,...
Read more >An Adaptive Join Regression - ORDER BY (SELECT NULL)
Adaptive joins are a new feature in SQL Server 2017. For adaptive join ... 4. 5. 6. 7. 8. SELECT *. FROM dbo.MY_FIRST_CCI...
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
Oh you’re right, thanks for your feedback. I’ve fixed it like that:
With the HTTP GET that remains the same. Thanks!
Even with the alias I am still getting this error.
Update:
I had to add an alias to ‘sections’, ‘sections.comments’, and ‘sections.comment.replies’, and not just ‘sections.comments’ and ‘sections.comment.replies’.
I am not sure, but this might be a bug in typeorm.I see that instead of breaking down the nested relation into multiple joins with aliases, the entire nested path is passed to Typeorm, and the cause of this issue.This call to
findRelationWithPropertyPath(this.relationPropertyPath)
fails withthis.relationPropertyPath
beingcomments.replies
. I would think that if you are searching within the parent alias, that it would be able to findcomments.replies
, unless it isn’t capable of handling that level of nesting.Further investigation, that call to
findRelationWithPropertyPath(this.relationPropertyPath)
is not capable of handling the nesting. In the screen shot,this.relations
only containspropertyPaths
likesections
, orcomments
–nothing likecomments.replies
, so this call returns nothing.Update:
It seems this is by design in Typeorm. It wants you to turn that nesting into multiple joins with multiple aliases, such as the snippet below.
Here are the changes I ended up making to
@Crud
, and maybe its because I didn’t completely know how the aliases affected the other joins, but now it makes sense. It’s a mess right now, but Take note of how I am chaining the joins together with the aliases:sections.comments
becomessections_comments
, andsections.comments.replies
becomessections_comments.replies
, and so on.Sorry for the length of this comment, but I am working late on some code needed for tomorrow.