From b57cb581dd900f1a4ece59bfb0dba326740dd5f4 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 23:05:56 +1030 Subject: [PATCH] #840 Eager load photos --- app/models/planting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index 900156b2a..14e9017cb 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -116,7 +116,7 @@ class Planting < ActiveRecord::Base interesting_plantings = Array.new seen_owners = Hash.new(false) # keep track of which owners we've seen already - Planting.all.each do |p| + Planting.includes(:photos).each do |p| break if interesting_plantings.size == howmany # got enough yet? if require_photo next unless p.photos.present? # skip those without photos, if required