Forum: Ruby on Rails Q: find :include

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2009-02-27 13:27
(Received via mailing list)
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 :)
Frederick C. (Guest)
on 2009-02-27 13:31
(Received via mailing list)
On 27 Feb 2009, at 11:26, removed_email_address@domain.invalid wrote:

>
>  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
vimal (Guest)
on 2009-02-27 13:32
(Received via mailing list)
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
(Guest)
on 2009-02-27 14:55
(Received via mailing list)
> 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...

So 2 queries is ok! :)

thanks guys
This topic is locked and can not be replied to.