-
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
[9.x] Model::whereRelation ignores the callback function or does it wrong #42465
Conversation
I agree I could have used a different method. For example "whereHas" instead of "whereRelation". I added tests for checks. I can improve them if needed in the next pull request. |
As I understand it, the last one who changed this code was Italo DarkGhostHunter. |
(checking...) |
Well, it's expected:
I don't remember why I didn't do that in the first place, I think it was because the callback was already handled by Eloquent |
@DarkGhostHunter I'm sorry I commented on you. I thought you should see. |
@GrahamCampbell "Changed name" Thanks for correcting me! |
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. |
We don't document using these methods this way. |
@taylorotwell I did an analogy. I agree it's not in the documentation. Example 1 (method has) In the last pull request you told me. The developer who implemented this method said. DarkGhostHunter: I don't remember why I didn't do that in the first place, I think it was because the callback was already handled by Eloquent where() and it doesn't replaces whereHas(), which is a convenience method for has() with a callback where you have more control. I have used this method. I needed to pass a callback function. I have read the documentation. But this was not in the documentation. I started looking for ways to do it differently. I found the answer not in the documentation. I looked at the source code. Found that this is a wrapper over whereHas. I thought. Why can't I pass a callback function properly? I don't know why you think the current addition is wrong. Tell me how it would be better. I'll fix it. |
// One is enough for me. Which will reduce the burden.
User::whereRelation("posts", function($query) {
$query->limit(1);
}) But I can't do that! Why? I can add documentation! |
@taylorotwell I think we're talking about a supplement. I'm not sure if this is a mistake. But many expect a different result using this method. |
please show this |
Eloquent
Query
Eloquent output
Query output