Wednesday, April 29, 2009

Re: how to order by hasmany-count (without query())

I have a similar system in place to what you have, although probably a
bit more business logic (who's to know though). The way CakePHP's
find works, any data that is calculated with an SQL method is placed
in a separate array, outside of the model. See:
http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/
(thanks teknoid!)

The example given should allow you to get closer to your goal so long
as your find()'s requirements are as simple as they sound. (I
resorted to using query() due to business logic which forced a join
type that I was uncertain on how to use within CakePHP's find() method
- but it is possible; I simply spent too much time on it.) It
*should* allow you to order your data by the calculated field, but
then you'd probably want to use teknoid's example of using Set::check
() to re-encapsulate the count to be associated with the specific
record you are counting.

On Apr 29, 6:56 am, CheshirePuss <CheshirePus...@gmail.com> wrote:
> Ok, I'm starting to think a seperate votes table is not the way to go.
> Just votes_up and votes_down added to the sounds table might be
> better, dropping the feature of knowing who voted for what. It's not
> so interesting anyways, and there is a lot more to find about doing it
> with one table, rather than with a seperate one.
> I'm still curious though how one would perform such a multi-table
> count-query with cakephp, but then again, maybe I should first be able
> to make the sql-query, which I also don't have a clue about.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: