You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! This package is awesome but I'm struggling to use it on large tables.
Doing a count() before calling the get() on a QueryBuilder, will always return 1 instead of the actual count.
So whenever you apply a whereJoin on a very large table, you first need to call get() before being able to do a count().
This is causing issues for me when I want to include the total count of matching records (for pagination) before applying a limit and offset.
public function get()
{
$query = User::query()
->whereJoin('comments.text', 'LIKE', 'This is comment number 999%');
return response()->json([
'count_without_get' => $query->count(), // returns 1
'count_with_get' => $query->get()->count() // returns 11
]);
}
Hello! This package is awesome but I'm struggling to use it on large tables.
Doing a
count()
before calling theget()
on a QueryBuilder, will always return1
instead of the actual count.So whenever you apply a
whereJoin
on a very large table, you first need to callget()
before being able to do acount()
.This is causing issues for me when I want to include the total count of matching records (for pagination) before applying a limit and offset.
I've created an example application to demonstrate the issue, run
composer test
for a simple test case.https://github.com/joostelders/eloquent-join-count-example
The text was updated successfully, but these errors were encountered: