mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 21:56:55 -04:00
More inverse relationships defined
This commit is contained in:
@@ -62,7 +62,7 @@ class Garden < ApplicationRecord
|
||||
unique_plantings = []
|
||||
seen_crops = []
|
||||
|
||||
plantings.order(created_at: :desc).includes(:garden, :crop, :owner, :harvests).each do |p|
|
||||
plantings.includes(:garden, :crop, :owner, :harvests).order(created_at: :desc).each do |p|
|
||||
unless seen_crops.include?(p.crop)
|
||||
unique_plantings.push(p)
|
||||
seen_crops.push(p.crop)
|
||||
|
||||
@@ -3,7 +3,8 @@ class Photo < ApplicationRecord
|
||||
|
||||
PHOTO_CAPABLE = %w(Garden Planting Harvest Seed).freeze
|
||||
|
||||
has_many :photographings, foreign_key: :photo_id, dependent: :destroy
|
||||
has_many :photographings, foreign_key: :photo_id, dependent: :destroy, inverse_of: :photo
|
||||
|
||||
# creates a relationship for each assignee type
|
||||
PHOTO_CAPABLE.each do |type|
|
||||
has_many type.downcase.pluralize.to_s.to_sym,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Photographing < ApplicationRecord
|
||||
belongs_to :photo
|
||||
belongs_to :photo, inverse_of: :photographings
|
||||
belongs_to :photographable, polymorphic: true
|
||||
|
||||
validate :photo_and_item_have_same_owner
|
||||
|
||||
@@ -21,10 +21,14 @@ class Planting < ApplicationRecord
|
||||
|
||||
#
|
||||
# Ancestry of food
|
||||
belongs_to :parent_seed, class_name: 'Seed', foreign_key: 'parent_seed_id',
|
||||
required: false # parent
|
||||
has_many :child_seeds, class_name: 'Seed',
|
||||
foreign_key: 'parent_planting_id', dependent: :nullify # children
|
||||
belongs_to :parent_seed, class_name: 'Seed', # parent
|
||||
foreign_key: 'parent_seed_id',
|
||||
required: false,
|
||||
inverse_of: :child_plantings
|
||||
has_many :child_seeds, class_name: 'Seed', # children
|
||||
foreign_key: 'parent_planting_id',
|
||||
inverse_of: :parent_planting,
|
||||
dependent: :nullify
|
||||
|
||||
##
|
||||
## Scopes
|
||||
|
||||
Reference in New Issue
Block a user