If an application is not linked to any executable it wont be returned (because of the join clause).
May 19, 2016
18
Level 1
->groupBy()->count() returns wrong value
I have problem joining other table, and grouping it by ID, Both queries returns same amount of collection, yet, if i try to get (count()), one which is grouped by, returns 18, while other returns 101, (I have 101 rows in database). Any ideas why count doesn't work properly, and how should I fix it?
$result = Application::where(function ($query) use ($string) {
$query->orWhere('name', 'LIKE', $string)->orWhere('description', 'LIKE', $string);
});
$result2 = Application::leftJoin('executables', 'executables.application_id', '=', 'applications.id')->where(function ($query) use ($string) {
$query->orWhere('applications.name', 'LIKE', $string)->orWhere('applications.description', 'LIKE', $string);
})->select('applications.*', 'executables.name AS exe_name')->groupBy("applications.id");
$total = $result->count();
$total2 = $result2->count("applications.id");
dd($total, $total2);
Level 1
$applications2 = $result2->get();
$total2 = count($applications2); //returns correct value. I will assume there is bug in eloquent.
Please or to participate in this conversation.