From 3791b34fe31002aeb4e8b953c6e3c24cd0cea6d8 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 28 Mar 2017 22:36:21 +1300 Subject: [PATCH] One planting per owner (used for intersetingness) --- app/models/planting.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index e1c1c6d96..c7d98c7aa 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -12,8 +12,13 @@ class Planting < ActiveRecord::Base scope :finished, -> { where(finished: true) } scope :current, -> { where(finished: false) } - scope :interesting, -> { has_photos } - scope :has_photos, -> { joins(:photos).where("photos.id IS NOT NULL") } + scope :interesting, -> { has_photos.one_per_owner } + scope :one_per_owner, lambda { + joins("JOIN members m ON (m.id=plantings.owner_id) + LEFT OUTER JOIN plantings p2 + ON (m.id=p2.owner_id AND plantings.id < p2.id)").where("p2 IS NULL") + } + scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) } delegate :name, :en_wikipedia_url,