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…
Heh, I was just about to come back with essentially the same answer (using Cake’s Model::find):
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.