I'm not absolutely certain of this but it's worth trying.
Given an aray of tags to match, $tags = array('Cake', 'PHP') ...
$posts = $this->Post->find(
'all',
array(
'conditions' => array(
'Tag.body' => $tags
)
)
);
Or, if that doesn't work, you could just iterate through your tags and
add them to the AND conditions:
$conditions = array('AND' => array());
foreach($tags as $tag)
{
$conditions['And'][] = array('Tag.body' => $tag);
}
$posts = $this->Post->find(
'all',
array(
'conditions' => $conditions
)
);
But I'm fairly sure the first method will work.
On Tue, Aug 25, 2009 at 10:48 AM, harpax<[email protected]> wrote:
>
> Hi,
>
> Again a question on a habtm find and again the default example:
>
> Tag <-> TagPost <-> Post
>
> What I need to accomplish is a fairly easy thing (I thought), but
> somehow I don't seem to be able to do it. I would like to find all
> Posts that match 2 (or more) tags, so for example all Post with the
> tags 'Cake' AND 'PHP' associated. So far I only had 'OR' queries
> (tag_id IN (1, 2, ..)) and as mentioned before I don't have a clue
> right now..
>
> Thanks a lot,
> harpax
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---