Guest User

Untitled

a guest
Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. SELECT *
  2. FROM group_buys GroupBuy
  3. LEFT JOIN group_buy_users GroupBuysUser
  4. ON GroupBuysUser.group_buy_id = GroupBuy.id
  5. LEFT JOIN (
  6. SELECT group_buy_id, COUNT(user_id) as Count
  7. FROM group_buy_users
  8. GROUP BY group_buy_id
  9. ) GroupBuysUserCount
  10. ON GroupBuysUserCount.group_buy_id = GroupBuy.id
  11. LEFT JOIN group_buy_merchant_offers GroupBuysMerchantOffer
  12. ON GroupBuysMerchantOffer.group_buy_id = GroupBuy.id
  13. WHERE GroupBuysUser.user_id = {$this->Auth->user('id')}
  14. GROUP BY GroupBuy.id
  15. HAVING GroupBuy.expiry_date > NOW()
  16.  
  17. $options = array(
  18. 'joins' => array(
  19. array(
  20. 'table' => 'group_buys',
  21. 'alias' => GroupBuy,
  22. 'type' => 'LEFT',
  23. 'conditions' => array('GroupBuysUser.group_buy_id = GroupBuy.id')
  24. ),
  25. array(
  26. 'table' => 'group_buy_merchant_offers',
  27. 'alias' => GroupBuysMerchantOffer,
  28. 'type' => 'LEFT',
  29. 'conditions' => array('GroupBuysMerchantOffer.group_buy_id = GroupBuy.id')
  30. ),
  31. 'conditions' => array('GroupBuysUser.user_id' => $this->Auth->user('id')),
  32. 'group' => array('GroupBuy.id HAVING GroupBuy.expiry_date > NOW()')
  33. )
  34. );
  35.  
  36. $this->paginate = $options;
  37. $groups = $this->paginate('Group');
  38. $this->set('groups', $groups);
Add Comment
Please, Sign In to add comment