foreign key declarations not needed anymore

This commit is contained in:
Brenda
2020-08-02 08:30:10 +12:00
committed by Brenda Wallace
parent 15d72d3769
commit 5573fbfbb6
5 changed files with 7 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

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