Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 36023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:19:41+00:00 2026-05-10T14:19:41+00:00

As part of a larger web-app (using CakePHP), I’m putting together a simple blog

  • 0

As part of a larger web-app (using CakePHP), I’m putting together a simple blog system. The relationships are exceedingly simple: each User has a Blog, which has many Entries, which have many Comments.

An element I’d like to incorporate is a list of ‘Popular Entries.’ Popular Entries have been defined as those with the most Comments in the last month, and ultimately they need to be ordered by the number of recent Comments.

Ideally, I’d like the solution to stay within Cake’s Model data-retrieval apparatus (Model->find(), etc.), but I’m not sanguine about this.

Anyone have a clever/elegant solution? I’m steeling myself for some wild SQL hacking to make this work…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:19:42+00:00Added an answer on May 10, 2026 at 2:19 pm

    Heh, I was just about to come back with essentially the same answer (using Cake’s Model::find):

    $this->loadModel('Comment');  $this->Comment->find( 'all', array(     'fields' => array('COUNT(Comment.id) AS popularCount'),     'conditions' => array(         'Comment.created >' => strtotime('-1 month')     ),     'group' => 'Comment.blog_post_id',     'order' => 'popularCount DESC',      'contain' => array(         'Entry' => array(             'fields' => array( 'Entry.title' )         )     ) )); 

    It’s not perfect, but it works and can be improved on.

    I made an additional improvement, using the Containable behaviour to extract the Entry data instead of the Comment data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my Android app to take a picture, as part of something larger
We are using Rails 3.0.X and running our web app on Heroku. We are
I am creating a small number of JSON Web Services using JsonResult as part
I have the following code as part of a larger web application to search
I've got a silverlight app installed as a web part feature in a sharepoint
I have a Content Editor Web Part where I am using scrolling Javascript to
I am working on a large web application implemented in ASP.net. The main part
As part of a larger series of operations, I'm trying to take tokenized chunks
As part of a larger task performed in R run under windows, I would
As a part of a larger application I need to implement an SSL tunnel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.