Why don't you simply add another column to your posts table and name it
num_views or something, and increment this field by 1 every time a post is
being viewed, this will save you the hassle of combining 2 models in your
posts controller plus there will be no DB tables joins while you retrieve
the desired number of views for a certain post, in other hand, if you wanted
to apply the find on the current approach that you use, if you were using a
belongsTo relation "PostView belongsTo Post" then setting the "recursive"
flag for the PostView model to 1 and then doing a simple find process will
do the job for you

2009/10/17 Jesús Ángel <[email protected]>

>
> Hi.
>
> The main model is a Post. A post hasMany Postview.
>
> I need to get the most viewed (popular) posts.
>
> I'm hoping to use Model::find() to build this query (or something like
> it..):
>
> select
>        Post.id,
>        Post.name,
>        Post.slug,
>        count(Postview.id) as views
> from
>        posts AS Post,
>        postviews AS Postview
> where
>        Post.id = Postview.post_id
> group by Post.id
> order by views desc
> limit ' . $limit
>
> Could you please help me?
>
> Thanks
>
>
> >
>


-- 
http://phpirate.net

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to