So I have....
class Post < ActiveRecord::Base
belongs_to :user
end
@posts = Post.find :all, :include=>:user
.... but when I look at my logs I see this:
Post Load (2.4ms) SELECT * FROM `posts`
User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 1)
I was expecting one combined SQL statement?
Any ideas?
thanks :)
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 27 Feb 2009, at 11:26, rails.nerd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > So I have.... > > class Post < ActiveRecord::Base > belongs_to :user > end > > @posts = Post.find :all, :include=>:user > > .... but when I look at my logs I see this: > > Post Load (2.4ms) SELECT * FROM `posts` > User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 1) > > I was expecting one combined SQL statement? >Not since rails 2.1 Fred> Any ideas? > thanks :) > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
what exactly do you want to do??? for me it looks like you want all the posts for the particular user then it should be @posts = User.posts --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rails.nerd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Feb-27 12:54 UTC
Re: Q: find :include
> what exactly do you want to do???I just didn''t want to make a new query everytime i accessed a user of a post However, Fred is right http://www.akitaonrails.com/2008/5/26/rolling-with-rails-2-1-the-first-full-tutorial-part-2 So 2 queries is ok! :) thanks guys --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---