Skip to content

chore set belongs_to_required_by_default to true in config #2259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/address.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Address < ApplicationRecord
belongs_to :sponsor
belongs_to :sponsor, optional: true
end
2 changes: 1 addition & 1 deletion app/models/attendance_warning.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AttendanceWarning < ApplicationRecord
belongs_to :member
belongs_to :issued_by, class_name: 'Member', foreign_key: 'sent_by_id', inverse_of: false
belongs_to :issued_by, class_name: 'Member', foreign_key: 'sent_by_id', inverse_of: false, optional: true

scope :last_six_months, -> { where(created_at: 6.months.ago...Time.zone.now) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/auth_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AuthService < ApplicationRecord
belongs_to :member
belongs_to :member, optional: true
validates :uid, uniqueness: { constraint: :provider }
end
2 changes: 1 addition & 1 deletion app/models/ban.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Ban < ApplicationRecord
belongs_to :member
belongs_to :member, optional: true
belongs_to :added_by, class_name: 'Member'

validates :expires_at, :reason, :note, :added_by, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/contact.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'services/mailing_list'
class Contact < ApplicationRecord
belongs_to :sponsor
belongs_to :sponsor, optional: true

validates :name, :surname, :email, presence: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Event < ApplicationRecord

resourcify :permissions, role_cname: 'Permission', role_table_name: :permission

belongs_to :venue, class_name: 'Sponsor'
belongs_to :venue, class_name: 'Sponsor', optional: true
has_many :sponsorships
has_many :sponsors, -> { where('sponsorships.level' => nil) }, through: :sponsorships, source: :sponsor
has_many :bronze_sponsors, -> { where('sponsorships.level' => 'bronze') }, through: :sponsorships, source: :sponsor
Expand Down
2 changes: 1 addition & 1 deletion app/models/feedback.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Feedback < ApplicationRecord
belongs_to :tutorial
belongs_to :coach, class_name: 'Member'
belongs_to :workshop
belongs_to :workshop, optional: true
has_one :chapter, through: :workshop

validates :rating, inclusion: { in: 1..5, message: "can't be blank" }
Expand Down
2 changes: 1 addition & 1 deletion app/models/feedback_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class FeedbackRequest < ApplicationRecord
belongs_to :member
belongs_to :workshop
belongs_to :workshop, optional: true

validates :member_id, presence: true, uniqueness: { scope: [:workshop] }
validates :workshop, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Invitation < ApplicationRecord

belongs_to :event
belongs_to :member
belongs_to :verified_by, class_name: 'Member'
belongs_to :verified_by, class_name: 'Member', optional: true

validates :event, :member, presence: true
validates :member_id, uniqueness: { scope: %i[event_id role] }
Expand Down
4 changes: 2 additions & 2 deletions app/models/meeting_talk.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MeetingTalk < ApplicationRecord
belongs_to :speaker, class_name: 'Member'
belongs_to :meeting
belongs_to :speaker, class_name: 'Member', optional: true
belongs_to :meeting, optional: true

validates :title, :abstract, :speaker, :meeting, presence: true

Expand Down
4 changes: 2 additions & 2 deletions app/models/member_note.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MemberNote < ApplicationRecord
belongs_to :member
belongs_to :author, class_name: 'Member'
belongs_to :member, optional: true
belongs_to :author, class_name: 'Member', optional: true

validates :member, :author, :note, presence: true
end
2 changes: 1 addition & 1 deletion app/models/permission.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Permission < ApplicationRecord
has_and_belongs_to_many :members, join_table: :members_permissions
belongs_to :resource, polymorphic: true
belongs_to :resource, polymorphic: true, optional: true

scopify
end
2 changes: 1 addition & 1 deletion app/models/tutorial.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Tutorial < ApplicationRecord
belongs_to :workshop
belongs_to :workshop, optional: true

validates :title, presence: true
default_scope -> { order(:created_at) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/workshop_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class WorkshopInvitation < ApplicationRecord

belongs_to :workshop
belongs_to :member
belongs_to :overrider, foreign_key: :last_overridden_by_id, class_name: 'Member', inverse_of: false
belongs_to :overrider, foreign_key: :last_overridden_by_id, class_name: 'Member', inverse_of: false, optional: true
has_one :waiting_list, foreign_key: :invitation_id

validates :workshop, :member, presence: true
Expand Down
4 changes: 1 addition & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ class Application < Rails::Application
# More info at https://skylight.io/support/environments
config.skylight.environments << 'development'

# TODO: sort this out properly at
# See https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#active-record-belongs-to-required-by-default-option
config.active_record.belongs_to_required_by_default = false
config.active_record.belongs_to_required_by_default = true
end
end

Expand Down