belongs_to defaults to required. setting some to optional

This commit is contained in:
Brenda Wallace
2018-01-04 14:55:36 +13:00
parent 2fd13e9b7c
commit 090bc02269
3 changed files with 4 additions and 4 deletions

View File

@@ -17,8 +17,8 @@ class Crop < ApplicationRecord
has_many :harvests
has_many :plant_parts, -> { uniq.reorder("plant_parts.name") }, through: :harvests
belongs_to :creator, class_name: 'Member'
belongs_to :requester, class_name: 'Member'
belongs_to :parent, class_name: 'Crop'
belongs_to :requester, class_name: 'Member', optional: true
belongs_to :parent, class_name: 'Crop', optional: true
has_many :varieties, class_name: 'Crop', foreign_key: 'parent_id'
has_and_belongs_to_many :posts # rubocop:disable Rails/HasAndBelongsToMany

View File

@@ -35,7 +35,7 @@ class Harvest < ApplicationRecord
belongs_to :crop
belongs_to :owner, class_name: 'Member', counter_cache: true
belongs_to :plant_part
belongs_to :planting
belongs_to :planting, optional: true
##
## Scopes

View File

@@ -6,7 +6,7 @@ class Post < ApplicationRecord
#
# Relationships
belongs_to :author, class_name: 'Member'
belongs_to :forum
belongs_to :forum, optional: true
has_many :comments, dependent: :destroy
has_and_belongs_to_many :crops # rubocop:disable Rails/HasAndBelongsToMany
# also has_many notifications, but kinda meaningless to get at them