H
harm.hoekstra
Hi,
I want to make a RoR webapp and on one screen the user should see
products and his/her own rating:
PRODUCT YOUR RATING
product100 <no rating yet, add rating widget>
product101 ****
product102 **
product103 <no rating yet, add rating widget>
...
So I have a listing over products, but I need to join in the ratings of
the current user (not of other users).
I think there are 2 approaches:
A. Add a getter method to the model to get the rating (filtered on
current user)
B. Make a view from SELECT * from products LEFT JOIN ratings ON
products.id = ratings.product_id AND
ratings.user_id = {user.id}
I guess method A will result in 20 queries being fired when a list of
20 are shown. Not that the webapp will have heavy traffic, but its a
more clean approach if the database does the heavy lifting in one
swoop, I think.
So I incline to B, but are there any pitalls when making a activerecord
model on basis of a VIEW ?
Or perhaps even better solutions are already thought out in Rails.
Thanks in advance,
Harm
I want to make a RoR webapp and on one screen the user should see
products and his/her own rating:
PRODUCT YOUR RATING
product100 <no rating yet, add rating widget>
product101 ****
product102 **
product103 <no rating yet, add rating widget>
...
So I have a listing over products, but I need to join in the ratings of
the current user (not of other users).
I think there are 2 approaches:
A. Add a getter method to the model to get the rating (filtered on
current user)
B. Make a view from SELECT * from products LEFT JOIN ratings ON
products.id = ratings.product_id AND
ratings.user_id = {user.id}
I guess method A will result in 20 queries being fired when a list of
20 are shown. Not that the webapp will have heavy traffic, but its a
more clean approach if the database does the heavy lifting in one
swoop, I think.
So I incline to B, but are there any pitalls when making a activerecord
model on basis of a VIEW ?
Or perhaps even better solutions are already thought out in Rails.
Thanks in advance,
Harm