diff --git a/app/models/concerns/ownable.rb b/app/models/concerns/ownable.rb index 8dac572a5..f6405ddc6 100644 --- a/app/models/concerns/ownable.rb +++ b/app/models/concerns/ownable.rb @@ -4,8 +4,7 @@ module Ownable extend ActiveSupport::Concern included do - belongs_to :owner, class_name: 'Member', - foreign_key: 'owner_id', counter_cache: true + belongs_to :owner, class_name: 'Member', counter_cache: true default_scope { joins(:owner).merge(Member.kept) } # Ensures the owner still exists end diff --git a/app/models/photo.rb b/app/models/photo.rb index 18cf971f7..64bf79348 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -7,7 +7,7 @@ class Photo < ApplicationRecord PHOTO_CAPABLE = %w(Garden Planting Harvest Seed Post Crop).freeze - has_many :photo_associations, foreign_key: :photo_id, dependent: :delete_all, inverse_of: :photo + has_many :photo_associations, dependent: :delete_all, inverse_of: :photo # This doesn't work, ActiveRecord tries to use the polymoriphinc photographable # relationship instead. diff --git a/app/models/planting.rb b/app/models/planting.rb index dc73b196c..3247fc015 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -25,10 +25,9 @@ class Planting < ApplicationRecord # # Ancestry of food - belongs_to :parent_seed, class_name: 'Seed', # parent - foreign_key: 'parent_seed_id', - optional: true, - inverse_of: :child_plantings + belongs_to :parent_seed, class_name: 'Seed', # parent, + optional: true, + inverse_of: :child_plantings has_many :child_seeds, class_name: 'Seed', # children foreign_key: 'parent_planting_id', inverse_of: :parent_planting, diff --git a/app/models/post.rb b/app/models/post.rb index 3a1dc548c..d84e2dc5d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -14,10 +14,10 @@ class Post < ApplicationRecord has_many :crop_posts, dependent: :delete_all has_many :crops, through: :crop_posts + after_create :send_notification # # Triggers after_save :update_crop_posts_association - after_create :send_notification default_scope { joins(:author).merge(Member.kept) } # Ensures the owner still exists diff --git a/app/models/seed.rb b/app/models/seed.rb index 2e853462f..761f40ffe 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -16,7 +16,7 @@ class Seed < ApplicationRecord # # Relationships belongs_to :crop - belongs_to :parent_planting, class_name: 'Planting', foreign_key: 'parent_planting_id', + belongs_to :parent_planting, class_name: 'Planting', optional: true, inverse_of: :child_seeds # parent has_many :child_plantings, class_name: 'Planting', foreign_key: 'parent_seed_id', dependent: :nullify,