Friday, October 30, 2009

RE: HABTM query - count number of related entries

I did something similar where I took the Post.id being viewed and extracted
the 'Tags' for that Post then did a find on Posts that had the same tags
using the Ad Hoc Joins Article in the bakery.

Not sure if it the best way but it worked for what I needed it for.

Dave

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Rick
Sent: October-30-09 10:57 AM
To: CakePHP
Subject: Re: HABTM query - count number of related entries


What are the field names of the related fields? I.e. Tag.? ==
Stories_tags.? == Story.?

On Oct 30, 7:24 am, Daniel <theworldof...@gmail.com> wrote:
> Hi. I've got two models, Tag and Story, each with a HABTM relation
> with each other (joined via a stories_tags table).
>
> What I'm looking for is the ability to do a find('all') on the Tag
> model, and within the results have a count of all the stories that are
> related to each tag.
>
> Is this possible to do? Thank you.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: