Skip to content

Instantly share code, notes, and snippets.

@anroots
Created August 14, 2012 13:14
Show Gist options
  • Save anroots/3349151 to your computer and use it in GitHub Desktop.
Save anroots/3349151 to your computer and use it in GitHub Desktop.
SQL vs ORM
<?php
// ...
/**
* Check if an employee has the training $training_id
*
* @since 2.2.3
* @static
* @param int $employee_id
* @param int $training_id
* @return bool
*/
public static function has_training($employee_id, $training_id)
{
// Current, native SQL
return (bool) DB::select('employee.id')
->from('employee')
->join('training_registration')
->on('employee.id', '=', 'training_registration.employee_id')
->join('training_schedule')
->on('training_schedule.id', '=', 'training_registration.schedule_id')
->where('employee.id', '=', $employee_id)
->where('training_schedule.training_id', '=', $training_id)
->execute()
->count();
// Better, ORM solution
return $this->has('training',$training_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment