-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.4] whereHas on polymorphic relations not work #18523
Comments
@lkmadushan what's the output? any error? or does it give an empty response? |
Please provide more details, |
Sorry. I have updated the description. Currently whereHas on polymorphic relations doesn't add constraints to the relationship query. It always check existence in same table. |
This won't be an easy fix afaik, we'll need to run several queries on several related tables in order for this work. |
This is related to #5429. There are some workarounds discussed there, like this one: #5429 (comment) It's a known limitation that won't probably be easy to fix. Workarounds indeed work but they involve some tricky engineering. |
Marked as No-fix when polimorph relations has not intersect collumns |
i'm currently using this code in my own project my Model (\App\Production\Models\Production Model)
my Controller
and it works for my use case. please note that all model related to \App\Production\Models\Production model have 'panen_future_date' filed in its table. |
@bunnypro can you try it on a new project with just the STR (steps to reproduce), it will be better :) |
i forgot to compare the _type filed. ok i'll try to repoduce it with fresh laravel project and also comparing the _type filed. |
i have reproduced in a fresh laravel project. here is the https://github.com/bunnypro/querying-polymorphic just migrate and use DummySeeder class for seeding. |
Do you get the same issue or not? |
yes i do |
Ppl, code:
and It's the code to return object to view:
The hint and the strange thing on the same is:
If I do this loop, for NOTHING, it work well and i can use on blade it:
and it on vue:
I hope it help |
@themsaid I've thought of a semi-solution after discussing this with another developer. It does have a fairly big caveat, but I still think it's better than nothing... Basically: Prerequisite: Solution: [
User::class,
Post::class,
Comment::class,
] We know that the If the [
'user' => User::class,
'post' => Post::class,
'comment' => Comment::class,
] We cannot be sure what the table name is. As such, the solution is... Ugly. We can loop over the morph map, running |
@bunnypro your solution is good. |
@staudenmeir - does your merged PR fix this issue? Can I close it? |
@laurencei The issue itself is basically unfixable, my PR just added a proper exception. I think this can be closed. |
Laravel 5.8.27 adds |
Description:
when try whereHas method on a polymorphic relation does not works as expected.
The text was updated successfully, but these errors were encountered: