I have the following query which should be finding:
- A row where the user_id matches userId and friend_id matches friendId
- OR a row where the user_id matches friendId and friend_id matches userId
- AND both also have status of 1
My code is:
public function isFriend($userId, $friendId)
{
return $search = $this->Friend->find('first', array(
'conditions'=>array(
'OR' => array(
'AND'=>array(
'Friend.user_id'=>$userId,
'Friend.friend_id'=>$friendId
),
'AND'=>array(
'Friend.user_id'=>$friendId,
'Friend.friend_id'=>$userId
)
),
'AND' => array(
'Friend.status'=>1
)
)
)
);
}
However it’s not working… I’ve looked around and seems it’s to do with getting the arrays correctly when dealing with the two AND calls, but I don’t get it. Can anyone help me out?
Thanks
You can’t use the same array key twice as mark said, so you have to encapsulate the ANDs in separate arrays