-
Notifications
You must be signed in to change notification settings - Fork 11k
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.1] [5.2] Polymorphic relation naming is inconsistent #10501
Comments
To clarify, if I don't eager load the relation first, then naming is consistent (using camel case). |
Did you try to change |
👍 this seems to be an issue only with |
I suspect the issue is at
the method seems suspiciously empty for what should be more complex than |
@joostbaptist I've come up with a solution, see PR #10864 , however I'm having a hard time understanding the logic in the unit test, I'll have another crack at it tomorrow, but I'm very open to suggestions on how to fix My change moves the registration of related models from the load eager into the |
Closing since there is a PR now. |
Hi all, thank you for looking into this. I found that changing the morphTo method in the Model class (https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Model.php#L847-L881) as shown below fixes the problem for me, although I'm not sure that it won't cause other problems. Thought I'd share this anyway, in case it might be helpful.
Note that I use the backtrace to extract the name of the relation ( |
Hey @joostbaptist, thanks for the update, to fill you in on the progress since this issue was last closed - I found the issue to be the api is inconsistent with when it registers the eager loading dictionary for This PR was merged and released, but then in #11138 it was found that my fix has somehow caused memory issues, which is surprising as the all the fix really does is align the Your solution might actually end up being the best option, as it doesn't affect the way the relationship works, and so should not cause the memory issue. Note that you can just do |
Hi All, Is it possible to remove the Str::snake here and just use the function caller name? The problem in consistency is the snake case the function caller. |
Hi,
Like #9427, I'm running into some strange naming behaviour with polymorphic relations. I would like to ask you to look at this again.
My polymorphic relation is defined as follows in class
Module
:Now, in order to load this relation, I have to call:
However, to retrieve this relation, I have to call:
This clearly shows that naming is inconsistent. All relations are named using camel case and it seems that only polymorphic relations are named using snake case.
Here is another example that clearly shows this inconsistent behaviour:
Below is a screenshot that shows the result of executing the above code:
Also note that another empty relation ('moduleInstance') is added using an actually consistent name.
Thanks in advance!
The text was updated successfully, but these errors were encountered: