So I've been going through the Simply Rails 2 book and built the example app and have been playing around, extending and modifying it for practice.

I have been struggling for a couple days on how-to see if a user has voted on the story while loading the Stories#index without having to do a separate sql call for each story fetched (I figured that out). I don't think it's optimal to do a all those sql queries on index load.

Since the tables all have relationships I'd think it would be possible but can't figure it out. Any thoughts?

If you don't have the book the tables and relevant cols are as follows:

table stories (belongs_to :user, has_many :votes)iduser_id

table users (has_many: stories, has_many :votes)id

table votes (belongs_to: stories, belongs_to :user)idstory_iduser_id

When I load the 10 (20, 30) articles from the Stories#index I would like to know if the logged_in? user has voted on the story. Once again without doing a sql call for each story.