Add missing foreign key constraints and set correct on delete behaviour

This commit is contained in:
Petko Bordjukov 2019-04-28 21:07:33 +03:00
parent c40f65fade
commit 992ede0735
2 changed files with 42 additions and 2 deletions

View File

@ -18,11 +18,11 @@ class Conference < ActiveRecord::Base
has_many :conflict_counts, through: :events
has_many :volunteer_teams
has_many :volunteers
has_one :call_for_participation, dependent: :destroy
has_one :call_for_participation
has_many :participants, -> { distinct }, class_name: 'User', through: :events
has_many :participant_profiles, class_name: 'PersonalProfile'
has_many :slots, through: :halls
has_many :feedbacks, as: :feedback_receiving, dependent: :destroy
has_many :feedbacks, as: :feedback_receiving
has_many :editions, primary_key: :host_name, foreign_key: :host_name, class_name: 'Conference'
has_many :events_of_all_editions, through: :editions, source: :events

View File

@ -0,0 +1,40 @@
class AddReferentialIntegrity < ActiveRecord::Migration[5.2]
def change
remove_foreign_key :call_for_participations, :conferences
add_foreign_key :call_for_participations, :conferences, on_delete: :cascade
add_foreign_key :conference_translations, :conferences, on_delete: :cascade
add_foreign_key :conflict_counts, :events, column: :left_id, on_delete: :cascade
add_foreign_key :conflict_counts, :events, column: :right_id, on_delete: :cascade
add_foreign_key :event_type_translations, :event_types, on_delete: :cascade
remove_foreign_key :event_types, :conferences
add_foreign_key :event_types, :conferences, on_delete: :cascade
add_foreign_key :hall_translations, :halls, on_delete: :cascade
add_foreign_key :halls, :conferences, on_delete: :cascade
add_foreign_key :personal_profiles, :users, on_delete: :cascade
add_foreign_key :personal_profiles, :conferences
add_foreign_key :propositions, :users, column: :proposer_id
add_foreign_key :slots, :halls, on_delete: :cascade
add_foreign_key :slots, :events, on_delete: :nullify
add_foreign_key :track_translations, :tracks, on_delete: :cascade
add_foreign_key :tracks, :conferences, on_delete: :cascade
add_foreign_key :volunteer_team_translations, :volunteer_teams, on_delete: :cascade
remove_foreign_key :volunteer_teams, :conferences
add_foreign_key :volunteer_teams, :conferences, on_delete: :cascade
add_foreign_key :volunteer_teams_volunteers, :volunteers, on_delete: :cascade
add_foreign_key :volunteer_teams_volunteers, :volunteer_teams, on_delete: :cascade
end
end