Filtering Included Relationships not working with IQuery "where" method
See original GitHub issueThe documentation mentions the following:
Filtering Included Relationships
Similarly, you may filter included relationships using where(), and(), and or().
this._userRepository
.include(u => u.posts)
.where(p => p.archived)
This doesn’t seem to work with “where”, the inferred type is User, but it works with and/or and post is inferred.
I have been using “and” as a workaround in most cases and it works fine. Not knowing the internals of the code (or tested in depth) the concerns I have are:
- could it be causing other undesirable side effects or is it just the typings?
- a little bit of readability of the query is lost, which I think would be valuable since there is already some level of implicit nesting in the library.
- In case it’s hard to fix, it would be cool if the docs point out the limitation
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Filter functions do not work on relationships #12725 - GitHub
Any functions applied in the filter on relationships fail to execute correctly. This is seems to be both an app issue and api...
Read more >Laravel eloquent where filter HasMany relationship not ...
First at all with function of eloquent it's look like as LEFT JOIN on MYSQL so if you want only your teams where...
Read more >Solved: Relationship filtering on many to one doesnt filte...
Solved: Hi, I have several tables all linked to each other. What I am finding is that the filtering from many to one...
Read more >Relationship troubleshooting guidance - Power BI
BLANK groupings or slicer/filter items appear, and the source columns don't contain BLANKs, - It's a regular relationship, and "many"-side column contain values ......
Read more >Filtering Results Using Filtered Include Method in EF Core
In this article, we are going to show you how to use Filtered Include method in EF Core to filter results inside the...
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 updated the documentation (version
1.0.0-alpha.15
) and am going to go ahead and close this issue. I will try to figure something out if somebody opens it back up.Ah… I see what’s going on. The Query class allows for it, but the interface does not.
My intention (some time after the time at which the initial documentation was written) was for
include
to not behave like ajoin
when usingwhere
.My thought was this:
I think the reason I did that was because “include where” didn’t make a lot of sense to me in the sense that doing it the same way as “join where” would yield unexpected results - i.e. “include where” would not give you all users with filtered posts as you might expect, but rather would filter your user results like a “join where” would.
Obviously, given the way it works now, the documentation is extremely misleading and I will update it. I also wonder if “include where” should be allowed, but rather than doing an inner join as “include where” does, it would do a left join to produce the expected results discussed above.
The problem that presents, however, is that would break the way
include().where()
works now, so it would probably be best to not change the behavior, but rather just update the documentation.I guess the workaround that will be explained in the updated documentation is to use
.include()
followed by.join().where()
afterwards:Hopefully, if and when I finally get around to making this work, these weird quirks will be made obsolete as more context can be deduced when parsing the
where
function.As a side note, I am surprised that using
and
without awhere
before it did not error or produce unexpected results. I may need to check into that as well.