Q: find :include

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 :slight_smile:

On 27 Feb 2009, at 11:26, [email protected] 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

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

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

So 2 queries is ok! :slight_smile:

thanks guys