I have not done any work within Cake using GROUP BY, AVG or SUM etc yet but immediately it strikes me that your running this query on the wrong model and not GROUPing your results to allow it to return any meaningful AVGs.
If you set debug to 2 and look at the queries being generated you will see that for your above query it will run one query to find all songs and then a query for each Song found to fetch its hasMany Ratings. In theory this could work I suppose, but it's obviously not and I would be looking to streamline the amount of queries generated anyway by running the query on the ratings table with AVG(Rating.value) GROUP BY Rating.song_id. If you contained Song you would get all your data but with just one generated query. To further streamline this though I would calculate the average using afterSave() and afterDelete() within your Rating model and save it in Song as you could then easily sort your song's by rating. HTH Paul 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
