@BryceSharp so if it's that way then it seems the only real reason would be for API design where you don't want to share that info because that is a significant performance hit
@thomaskim 350ms is the average (ran it multiple times)
I'm on a different computer now but here is the "raw" results from debugbar
For withCount('enrollments'):
select `course_sessions`.*, (select count(*) from `employee_enrollments` where `course_sessions`.`id` = `employee_enrollments`.`course_session_id` and `dropped` is null and `employee_enrollments`.`deleted_at` is null) as `enrollments_count` from `course_sessions` where `id` >= '1' and `id` <= '320' and `course_sessions`.`deleted_at` is null
That averages around 850ms
For with('enrollments') it runs two queries...
select * from `course_sessions` where `id` >= '1' and `id` <= '320' and `course_sessions`.`deleted_at` is null
averages around 1.5ms
select * from `employee_enrollments` where `dropped` is null and `employee_enrollments`.`course_session_id` in ('1', '2', '3', ... '318', '319', '320') and `employee_enrollments`.`deleted_at` is null
averages around 20ms
Overall page loads are around 1.2s using withCount() and under 500ms for with()
so even with the overhead of the extra data it's still faster... all im after is the count of enrollments but at this point it seems the best thing to do is the simply get length via JS (vue app)
Am i doing something wrong or is this just the way it has to be due to the large size of the relationship table?