Re: How to use 'group by' with paginate()?
On 16 Jul., 10:44, Miles J mileswjohn...@gmail.com wrote: Do you have a $paginate property in your controller? You should place the group within the model within the $paginate. Sorry for the late answer. Yes, there's $paginate in the controller: var $paginate = array( 'limit' = 10, 'order' = array('News.created' = 'desc') ); Could you help me with the group by? The result should be a table having all news-columns and a additional column with the number of comments related to this news-entry. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: How to use 'group by' with paginate()?
Oh, after all I think this was a stupid question. :) I just had to change the recursive-value to 1. Because of the hasMany relation the comments are listed in a sub-array. The number of comments was easy to find, simply use count() on this array. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: How to use 'group by' with paginate()?
Do you have a $paginate property in your controller? You should place the group within the model within the $paginate. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
How to use 'group by' with paginate()?
Hi I'm new to CakePHP and maybe it's a very stupid question. But I don't hope so :) My question is: How to use a group by clause with paginate()? Here's a short description of my project: Table 'news': Id, title, ... Table 'comments': Id, news_id, ... I want to query all news with the number of comments, which are related to this news-entry. After baking I got the following code: function index() { $this-News-recursive = 0; $this-set('news', $this-paginate('News')); } After reading the API (http://api.cakephp.org/class/controller#method- Controllerpaginate) I think, that I have to do this with some additional constructions. I thought of querying all number of comments with the related news-id: SELECT news_id, count( * ) AS counter FROM comments GROUP BY news_id This results in an easy-to-use table, which could be placed in an array. Then I could access the count with the news_id as a key. Is this a good idea in the world of CakePHP and how can I realize it? Thanks a lot --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---