The queries will likely be the same.. but you should check to see if
it loaded the company details _before_ you called @user.company.

You might try the following from script/console while tailing the log
file in another terminal.

ruby script/console
=>  User.find(2)

... check the log/development.log

=> User.find(2, :include => :company)

.... check log/development.log

Good luck!

Cheers,
Robby



On Tue, Aug 10, 2010 at 10:21 PM, Mike Disuza <[email protected]> wrote:
> Hi I have written code like this
>
> 1) Without :include
> My code is :-
> def user_details
>   �...@user=user.find(params[:id])
>   �...@[email protected]
> end
> Log Output:-
>
> Processing UsersController#user_details (for 127.0.0.1 at 2010-08-11
> 10:51:34) [GET]
>  Parameters: {"id"=>"2"}
>  User Columns (1.0ms)   SHOW FIELDS FROM `users`
>  User Load (0.4ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2)
>  Company Load (0.4ms)   SELECT * FROM `companies` WHERE
> (`companies`.user_id = 2) LIMIT 1
> Rendering template within layouts/users
> Rendering users/user_details
> Completed in 65ms (View: 48, DB: 2) | 200 OK
> [http://localhost/user_xml?id=2]
>
> 2) With Include:-
>  def user_details
>   �...@user=user.find(params[:id], :include=>:company)
>   �...@[email protected]
> end
> Log Output:-
> Processing UsersController#user_details (for 127.0.0.1 at 2010-08-11
> 10:53:13) [GET]
>  Parameters: {"id"=>"2"}
>  User Columns (1.2ms)   SHOW FIELDS FROM `users`
>  User Load (0.5ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2)
>  Company Load (0.3ms)   SELECT * FROM `companies` WHERE
> (`companies`.user_id = 2) LIMIT 1
> Rendering template within layouts/users
> Rendering users/user_details
> Completed in 13ms (View: 2, DB: 2) | 200 OK
> [http://localhost/user_xml?id=2]
>
> If you look at the both o/p there is a query on company table in both
> the cases.
>
> What is the difference?
>
> Thanks,
> Mike
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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.
>
>

-- 
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.

Reply via email to