Re: Pagination: Sort by count of related model (e.g. User - Posts)
Depending on how precise your information should be you can add a number_of_posts field to your users table and update the count periodically, you can also keep the field updated with database triggers, or create an action to run the update query from cakephp admin pages on demand. That's just another way of dealing with it. Regards On 13 jun, 13:11, DigitalDude e.blumsten...@googlemail.com wrote: Hey, I have a problem here and need to fix it. It's about the following situation: I have a model User that has a relation to some entrie, let's say Posts. I want to paginate the User-Model and add a counting of the user's posts to my index of Users. So I will have the following table- structure in my view: Id Name Posts Actions 2 Ben 5 view/edit/delete 5 Mary 8 view/edit/delete The first two columns are easy to sort, but HOW can I sort my paginated user-array by the count of the related Post-entries? I would really appreciate some help here, because I just cannot find a way to do this... :( Regards, DD Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Pagination: Sort by count of related model (e.g. User - Posts)
Hey, I have a problem here and need to fix it. It's about the following situation: I have a model User that has a relation to some entrie, let's say Posts. I want to paginate the User-Model and add a counting of the user's posts to my index of Users. So I will have the following table- structure in my view: Id Name Posts Actions 2 Ben 5 view/edit/delete 5 Mary8 view/edit/delete The first two columns are easy to sort, but HOW can I sort my paginated user-array by the count of the related Post-entries? I would really appreciate some help here, because I just cannot find a way to do this... :( Regards, DD Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Pagination: Sort by count of related model (e.g. User - Posts)
Ideally, you should be able to create post_count as a virtualField and then sort by that, by as the cookbook states, the paginator can't order by virtualFields of associated models, so you wouldn't be able to sort by it. But there are two simple workarounds for this: http://book.cakephp.org/view/1608/Virtual-fields On Jun 13, 4:11 am, DigitalDude e.blumsten...@googlemail.com wrote: Hey, I have a problem here and need to fix it. It's about the following situation: I have a model User that has a relation to some entrie, let's say Posts. I want to paginate the User-Model and add a counting of the user's posts to my index of Users. So I will have the following table- structure in my view: Id Name Posts Actions 2 Ben 5 view/edit/delete 5 Mary 8 view/edit/delete The first two columns are easy to sort, but HOW can I sort my paginated user-array by the count of the related Post-entries? I would really appreciate some help here, because I just cannot find a way to do this... :( Regards, DD Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Pagination: Sort by count of related model (e.g. User - Posts)
Would using the belongsTo models counterCache not be a better solution, so that it will not be necessary to perform the counting every time the users are listed with the post count? Mentioned in the CakePHP book at: http://book.cakephp.org/view/1042/belongsTo Enjoy, John On Jun 13, 3:42 pm, calvin cal...@rottenrecords.com wrote: Ideally, you should be able to create post_count as a virtualField and then sort by that, by as the cookbook states, the paginator can't order by virtualFields of associated models, so you wouldn't be able to sort by it. But there are two simple workarounds for this:http://book.cakephp.org/view/1608/Virtual-fields [snip] Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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