Alexey Poimtsev
Alexey Poimtsev

Reputation: 2847

Eager loading for globalize2 translations

i have 2 models - Issue and Answers (issue has many answers) and both have translations with globalize2. Every time i attempting to load Issue with answers via

@issue = Issue.find(params[:id])
@answers = @issue.answers

causes loading of translations for each Answer (1 sql query per Answer).

How can i optimize it?

Upvotes: 0

Views: 296

Answers (2)

Anatoly
Anatoly

Reputation: 15530

@answers = @issue.answers.all(:include => :answer_translations)

Upvotes: 0

Alexey Poimtsev
Alexey Poimtsev

Reputation: 2847

Solved with

@answers = @issue.answers.all(:include => :translations)

Upvotes: 0

Related Questions