muratguzel / letsrate

The best way to add rating capabilities to your rails application and your activerecord models.
http://letsrate.herokuapp.com
198 stars 234 forks source link

How to eager load rating_caches? #55

Open tispratik opened 10 years ago

tispratik commented 10 years ago

I have tried many different ways to eager load the rating caches for a users items. But can't seem to get it right. Can you please suggest?

RatingCache Load (0.3ms) SELECT "rating_caches".* FROM "rating_caches" WHERE "rating_caches"."cacheable_id" = $1 AND "rating_caches"."cacheable_type" = $2 AND "rating_caches"."dimension" IS NULL ORDER BY "rating_caches"."id" ASC LIMIT 1 [["cacheable_id", 89], ["cacheable_type", "Item"]]

(0.3ms) SELECT COUNT(*) FROM "rates" WHERE "rates"."rater_id" = $1 AND (("rates"."dimension" IS NULL AND "rates"."rateable_id" = 89 AND "rates"."rateable_type" = 'Item')) [["rater_id", 52]]

RatingCache Load (0.3ms) SELECT "rating_caches".* FROM "rating_caches" WHERE "rating_caches"."cacheable_id" = $1 AND "rating_caches"."cacheable_type" = $2 AND "rating_caches"."dimension" IS NULL ORDER BY "rating_caches"."id" ASC LIMIT 1 [["cacheable_id", 87], ["cacheable_type", "Item"]]

(0.4ms) SELECT COUNT(*) FROM "rates" WHERE "rates"."rater_id" = $1 AND (("rates"."dimension" IS NULL AND "rates"."rateable_id" = 87 AND "rates"."rateable_type" = 'Item')) [["rater_id", 52]]