Is there: enable work with ActiveRecord instances?

All examples: include for active loading are for class-level queries. I tried this on the model instance, and it still returned a bunch of requests - does it work on instance methods?

#in controller @emails = person.sent_emails(:include => [:recipient]) #in view render @emails # _email.html.erb partial <h1><%= email.recipient.name %></h1> <p> <%= email.content %> </p> #still issues a select * for emails, N+1 for recipients :/ 
+6
source share
1 answer

It looks a bit Rails 2ish, which I know, and may be the best Rails 3, but it works.

 @emails = person.sent_emails.find(:all, :include => :recipient) 

Edit: see BaroqueBobcat's comment for a better method in Rails 3

+3
source

Source: https://habr.com/ru/post/887575/


All Articles