Replies: 1 comment 3 replies
-
Isn't it posible to detect what key is missing and add it temperarly to the select list? The key is set in the relation that has been created in the modal and thereby known. In that case there will be never a missing key thats needed by a relation. afterwards its posible to return only the fields that are set in the select method? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Fix #2550
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.I think, this behavior differs from how raw sql queries would behave. They would actually throw an error in that case. An empty collection is a wrong result. That's not what I expect. Not throwing exceptions because the code does something is misleading. Users don't necessarily understand why they get an empty collection either. And not understanding something and not being told anything is worse in my opinion. If you have an exception, you can google it and ask questions on stackoverflow.
Some might argue, that adding an exception might be a breaking change. In that case, one might want to go for an
E_USER_NOTICE
instead.Others would rather automatically add the missing keys to the query but this might be unintuitive in my opinion.
Therefore, two changes have to be made:
src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
src/Illuminate/Database/Eloquent/Relations/Relation.php
Beta Was this translation helpful? Give feedback.
All reactions