diff --git a/app/models/question.rb b/app/models/question.rb index e086165..61eddd1 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -78,10 +78,12 @@ guidances = {} theme_ids = themes.collect{|t| t.id} if theme_ids.present? - GuidanceGroup.where(org_id: org.id).each do |group| + GuidanceGroup.includes(guidances: :themes).where(org_id: org.id).each do |group| group.guidances.each do |g| - g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g + g.themes.each do |theme| + if theme_ids.include? theme.id + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{theme.title}"] = g + end end end end