Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *
- FROM group_buys GroupBuy
- LEFT JOIN group_buy_users GroupBuysUser
- ON GroupBuysUser.group_buy_id = GroupBuy.id
- LEFT JOIN (
- SELECT group_buy_id, COUNT(user_id) as Count
- FROM group_buy_users
- GROUP BY group_buy_id
- ) GroupBuysUserCount
- ON GroupBuysUserCount.group_buy_id = GroupBuy.id
- LEFT JOIN group_buy_merchant_offers GroupBuysMerchantOffer
- ON GroupBuysMerchantOffer.group_buy_id = GroupBuy.id
- WHERE GroupBuysUser.user_id = {$this->Auth->user('id')}
- GROUP BY GroupBuy.id
- HAVING GroupBuy.expiry_date > NOW()
- $options = array(
- 'joins' => array(
- array(
- 'table' => 'group_buys',
- 'alias' => GroupBuy,
- 'type' => 'LEFT',
- 'conditions' => array('GroupBuysUser.group_buy_id = GroupBuy.id')
- ),
- array(
- 'table' => 'group_buy_merchant_offers',
- 'alias' => GroupBuysMerchantOffer,
- 'type' => 'LEFT',
- 'conditions' => array('GroupBuysMerchantOffer.group_buy_id = GroupBuy.id')
- ),
- 'conditions' => array('GroupBuysUser.user_id' => $this->Auth->user('id')),
- 'group' => array('GroupBuy.id HAVING GroupBuy.expiry_date > NOW()')
- )
- );
- $this->paginate = $options;
- $groups = $this->paginate('Group');
- $this->set('groups', $groups);
Add Comment
Please, Sign In to add comment