mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
19 lines
424 B
Ruby
19 lines
424 B
Ruby
# frozen_string_literal: true
|
|
|
|
class PlantPart < ApplicationRecord
|
|
extend FriendlyId
|
|
|
|
friendly_id :name, use: %i(slugged finders)
|
|
|
|
has_many :harvests, dependent: :destroy
|
|
has_many :crops, -> { joins_members.distinct }, through: :harvests
|
|
|
|
validates :name, presence: true, uniqueness: true
|
|
|
|
scope :joins_members, -> { joins("INNER JOIN members ON members.id = harvests.owner_id") }
|
|
|
|
def to_s
|
|
name
|
|
end
|
|
end
|