Last active
August 29, 2015 14:07
-
-
Save tareko/ae9fbe5a71e1a999f9a3 to your computer and use it in GitHub Desktop.
Very tedious db query
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
SELECT `Trade`.`status`, `Trade`.`user_id`, `Trade`.`user_status`, `Trade`.`token`, `Trade`.`shift_id`, `Shift`.`date`, `Shift`.`shifts_type_id`, `Shift`.`id`, `Trade`.`id` FROM `kitab`.`trades` AS `Trade` LEFT JOIN `kitab`.`shifts` AS `Shift` ON (`Trade`.`shift_id` = `Shift`.`id`) LEFT JOIN `kitab`.`trades_details` AS `TradesDetail` ON (`Trade`.`id` = `TradesDetail`.`trade_id`) WHERE ((`Trade`.`user_id` = 294) OR (`TradesDetail`.`user_id` = 294)) ORDER BY `Trade`.`status` ASC LIMIT 3 |
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
public function getTradesForUser($user, $conditions = array()) { | |
$trades = $this->find('all', array( | |
'conditions' => array ( | |
'OR' => array( | |
'Trade.user_id' => $user, | |
'TradesDetail.user_id' => $user) | |
), | |
'recursive' => -1, | |
'limit' => 2, | |
'order' => 'Trade.status ASC', | |
'fields' => array( | |
'status', | |
'user_id', | |
'user_status', | |
'token', | |
'shift_id'), | |
'joins' => array(array( | |
'table' => 'trades_details', | |
'alias' => 'TradesDetail', | |
'type' => 'LEFT', | |
'conditions' => array( | |
'Trade.id = TradesDetail.trade_id', | |
) | |
)), | |
'contain' => array( | |
'User' => array( | |
'fields' => array( | |
'name', | |
'id')), | |
'TradesDetail' => array( | |
'fields' => array( | |
'id', | |
'token', | |
'user_id', | |
'status'), | |
'User' => array( | |
'fields' => array( | |
'id', | |
'name')) | |
), | |
'Shift' => array( | |
'fields' => array( | |
'date', | |
'shifts_type_id'), | |
'ShiftsType' => array( | |
'fields' => array( | |
'location_id', | |
'times'), | |
'Location' => array( | |
'fields' => array( | |
'location') | |
) | |
) | |
) | |
) | |
)); | |
return $trades; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment