Get all likes of a user

#74 · closed · 1 comments

View on GitHub ↗

ughstudios

How can we create a function to get all things that a user is liking? Currently the only method I have is something like this: ``` def get_user_likes user = User.first our_likes = [] Activity.all.each do |activity| if user.likes?(activity) our_likes.push(activity) end end our_likes.uniq end ``` But this is doing like 1 select query for each and every one... This won't scale well.

Comments

cmer

Why not query the likes table directly and scope by user?