Thank you

I need to relate each view with a user, so I need a postview table. I
though that a views_count field in posts table wasn't needed, because I
could calculate it from the postview registers.

Nevertheless, your approach is simpler, so I'll do what you said.

I have read that CackePHP have a counterCache option in the belongsTo
that increments/decrements the count field whenever a new view is
saved/deleted:

http://book.cakephp.org/view/81/belongsTo

Bye

El sáb, 17-10-2009 a las 18:21 -0400, Ma'moon escribió:
> 
> 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