Hi,
I have a User model which has friends (User.friends with a user_id/friend_id join table called followings). Each user has events (the events table has a user_id column).
For an activity feed, I want to get an array with the last 20 events of the friends of the user. Right now I'm calling the last 20 events for each friend, sorting everything by date and just keeping the last 20 events.
How can I do that directly into the database so that I only need one request instead of one per friend?
Is there a way I can do that directly with Rails? Or should I use an SQL request?
Thank you,
Kevin