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

As part of a larger project I'm trying to implement a facility using JOGL
It's a part of larger code base, which forces -Werror on gcc. This warning
I need to configure Tomcat memory settings as part of a larger installation, so
Assuming self-registration is used to install components as part of a larger installer program,
Looking for a solution in bash (will be part of a larger script). Given
I have a small lightweight application that is used as part of a larger
I believe strongly in using unit-tests as part of building large multi-platform applications. We
I'm building a Zend-based Web app that will permit third-party extensions. Essentially, this application's
I've been developing a WCF web service using .NET 3.5 with IIS7 and it
I am going to work on a project where a fairly large web app

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.