Do i place .Includes( ) method before or after .find( )?

activerecord, ruby-on-rails, ruby-on-rails-3

Solution

You can typically swap the order on ActiveRecord association calls, but you can't do it in this case. find() returns the object itself, not a chainable scope.

If you were using a where clause, then the placement of the calls would not matter. You just need to ensure that you've added all the joins you need before the sql is actually executed.

Problem

Where do i put .include() method for a rails model, before or after find? ``` User.find(1).includes(:books) ``` or ``` User.includes(:books).find(1) ```

Original source