Complicated AR Relations

Hi,

I have 3 tables in the database:

tbl_products:

product_id | product_title

tbl_reviews - products reviews:

review_id | product_id

tbl_rates - each review has its own rates (like durability, design, features etc.):

rate_id | review_id | stars

I want to make a query that brings the average rates for each product.

The problem is that each product can have more than 1 review…so when I’m

using with() all I get is an array of reviews (but what I need is the average of ALL reviews rates).

How can I do this?

Thanks! :)

Anyone?

Thanks again.

Have you checked this? http://www.yiiframework.com/doc/guide/1.1/en/database.arr#statistical-query

And that whole doc http://www.yiiframework.com/doc/guide/1.1/en/database.arr

Once you truly understand how these relations work it is much easier to get specific data from them.