Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *
- FROM `tips`
- JOIN users ON users.id = tips.user_id
- JOIN friends_users ON tips.user_id = friends_users.friend_id
- WHERE (friends_users.user_id =2 or tips.user_id=2)
- LIMIT 0 , 30
- function findTipsByUserAndFriends($userId) {
- //FriendsUser is automagically created by CakePHP "with" association
- $conditions = array('FriendsUser.user_id'=>$userId);
- $fields = 'FriendsUser.friend_id';
- //get a list friend ids for the given user
- $friendIds = $this->Tip->User->FriendsUser->find('list', compact('conditions', 'fields'));
- //get list of all userIds for whom you want the tips
- $userIds = array($userId) + $friendIds;
- $conditions = array('Tip.user_id'=>$userIds);
- $tips = $this->Tip->find('all', compact('conditions'));
- return $tips;
- }
- $aCond = array(
- 'fields' => array(
- 'Discount.*'
- ),
- 'contain' => array(
- 'Event' => array(
- 'conditions' => array('Event.id' => $iEventId)
- )
- )
- );
- $aBulkDiscounts = $this->Discount->find('first', $aCond);
Add Comment
Please, Sign In to add comment