Complicated AR Relations


I have 3 tables in the database:


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! :)


Thanks again.

Have you checked this?

And that whole doc

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