I currently have two ORM related tables, employee and shift. I'm trying to create a query which allows me to find all employees who didn't have a shift record for a given date. The shift needs to be referenced by a $start_date much like the query below
You need a subquery for that. Problem is that ORM currently doesn't have the functionality to generate embedded sub-querys. So you need something like this (from the top of my head):
$shifts = \Model_Employee::query()
->related('shifts') ->where(\DB::expr('(SELECT COUNT(*) FROM `shifts` `a` WHERE `a`.`employee_id` = `t0`.`id`)'), '=', 0) ->where('shifts.start_time', '>', $start_date_dayBegin) ->where('shifts.start_time', '<', $start_date_dayEnd) ->get();
You might have to move the where's on time to the subquery and remove the related.