Poorly named Relationship Methods #44732
Unanswered
BrekiTomasson
asked this question in
Ideas
Replies: 1 comment
-
The same applies for the parameter names for the relationships like HasOne, HasMany etc. |
Beta Was this translation helpful? Give feedback.
0 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.
-
Whenever I'm querying a model to check the absence of a relationship, I have to slow down and remind myself what the method was called.
->whereHas('media')
is so obvious, so my first guess is always->whereHasNot('media')
... which obviously doesn't work. Then I remember that Laravel uses a contraction in the negated version, so I reach for->whereHasnt('media')
... which obviously also doesn't work. It's not until I'm on my third attempt that I realize that the right answer is the far more verbose (and far less obvious)->whereDoesntHave('media')
What I'm suggesting is that we follow in the footsteps of
->whereNull('email')
and->whereNotNull('email')
and implement simpleNot
-based aliases to all theDoesnt
-methods. We wouldn't have to rename anything, just alias them under the hood.Beta Was this translation helpful? Give feedback.
All reactions