-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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.3] Eloquent : withCount() overrides the $columns on get() #15576
Comments
Ping @barryvdh
|
That is what I mentioned in the PR as possible problem, which I don't have a nice solution for. We need to add a select, if we just add the new column, the default '*' gets ignored (which is more common). See replies from here: #13414 (comment) I think it should work when you explicitly use a User::select(['id', 'name'])->withCount('someRelation')->get(); |
Yes it works this way. |
Yes it works the way barryvdh said. |
Or perhaps add this to a note to the withCount docs? |
You could also use the "addSelect" instead of "select", that way you can put it after the "withCount".
|
There should be a note regarding this. I spent over an hour trying to figure this out why @Luis-Goncalves-Searchprof |
@clytras we're always welcoming PR's that improve the docs 👍 |
@driesvints I'm not aware of the Notes Markdown format that I should use to add one in Counting Related Models. If you do, please provide it here and I will make a PR for this. |
$query->paginate() overrides the select() method and brings everything. Any way around for paginated results? |
Description:
When using withCount() from eloquent Builder it ignores the $columns passed to the get() method and select all the columns.
Steps To Reproduce:
The text was updated successfully, but these errors were encountered: