-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[8.x] Add foreignKey and localKey to query if they are missing #38215
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
Conversation
if they are missing to ensure, eager loading can assign the results to the right parent/child
I'm currently not sure if the keys should be removed from the collection if the user didn't specify them in the first place (reversing the added keys from before executing the query |
@laravel What do you think of adding this change? |
this looks clean to me, |
@shaedrich prs in draft won't be reviewed and closed after a few days. Prs with failing tests will also be closed. Please make sure to have passing tests and a thorough description when submitting. |
Are you sure, the error is caused by my changes? Cause I didn't change anything route-related
|
i was talking about this one :
|
Oh, okay. I'll check that one!
That means, we make the test assert the opposite? |
you should rebase and force push your branch, you are not up to date. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this will fix tests issues
edit: it does not seems to be fixed, i don't know why
I don't think this would be enough, in some cases it would end up being I'd personally rather have an exception to let me know I forgot something as a query exception would rather than something magically correct the query for me with a probability to throw a wrench in some use case where there should be none. |
8.x was failing. Try rebasing again. |
@donnysim Exception was my first attempt. Got outvoted. |
Co-authored-by: Dries Vints <[email protected]>
@shaedrich try merging once more. Should be fixed now. |
Co-authored-by: Dries Vints <[email protected]>
Since laravel#38215, missing foreignKey and localKey will get added
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions! If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response. |
I still think it's something to think about it, perhaps not now, but worth writing it down somewhere for later use. |
… to ensure, eager loading can assign the results to the right parent/child
If I have something like this
Comment
just has an emptyattachments
array. I know, why this happens and that I can solve this, by adding 'id' to the 'select()` method call, but wouldn't it be good if Eloquent knew that it needs this key? Since there's no error message, the mistake is everything but obvious due to the abstraction Laravel and Eloquent have.