Both are a part of your conditions, so they both should be in that array.
$q = $this->Bookmark->find(
'first',
array(
'conditions' => array(
'Bookmark.user_id' => $userID,
'Bookmark.post_id' => $postID
),
'recursive' => -1
)
);
Cake defaults to using AND for anything in the conditions array. But,
if you needed to use OR, you'd do it thusly:
$q = $this->Bookmark->find(
'first',
array(
'conditions' => array(
'OR' => array(
'Bookmark.user_id' => $userID,
'Bookmark.post_id' => $postID
)
),
'recursive' => -1
)
);
So, the 1st example above is equivalent to this:
$q = $this->Bookmark->find(
'first',
array(
'conditions' => array(
'AND' => array(
'Bookmark.user_id' => $userID,
'Bookmark.post_id' => $postID
)
),
'recursive' => -1
)
);
On Sat, Apr 18, 2009 at 10:16 PM, Dave Maharaj :: WidePixels.com
<[email protected]> wrote:
> Can someone point out how to do an AND query?
>
> In a regular query it would be SELECT Bookmark.id FROM Bookmarks WHERE
> Bookmark.user_id = $userID AND Bookmark.post_id = $postID
>
> Just cant seem to figure it out... i just need to see if there is a result
> and pass it to the layout
>
> $q = $this->Bookmark->find('first', array(
> 'conditions', array('Bookmark.user_id' => $userID),
> 'AND' => array('Bookmark.post_id' => $postID),
> 'recursive' => -1));
>
> thanks
>
> Dave
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---