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)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.