On Feb 28, 5:24 pm, LeonS <[email protected]> wrote: > Hi, > > I'm trying to reduce my queries to the database so i use includes, but > there is produced a query every time and i can't see an improvement. > What does i'm doing wrong? > It's because you're calling find_by_xxx which will always cause a query. you could instead do match.match_tips.detect {|m| m.user_id == current_user.id}
Fred > In controller: > > @matches = @stage.matches.find(:all,:include => > [:team_1,:team_2, :match_tips]) > > In view: > > <% @matches.each do |match| %> > <% if @tipped_matches.include? match %> > <% tip = > match.match_tips.find_by_user_id(current_user.id) %> > ...... > > So the third line will produce every turn through the loop a query, > thats not good, how can i avoid that? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

