On Feb 28, 5:24 pm, LeonS
<leonard.stellbr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.