Created
August 14, 2012 13:14
-
-
Save anroots/3349151 to your computer and use it in GitHub Desktop.
SQL vs ORM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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