One planting per owner (used for intersetingness)

This commit is contained in:
Brenda Wallace
2017-03-28 22:36:21 +13:00
parent 5d58be110e
commit 3791b34fe3

View File

@@ -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,