Skip to content

Commit

Permalink
Revise Rails 5 belongs_to associations required by default
Browse files Browse the repository at this point in the history
  • Loading branch information
smolnar committed Oct 5, 2015
1 parent 50c4437 commit b10617a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/models/court.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class Court < ActiveRecord::Base
has_many :hearings
has_many :decrees

belongs_to :jurisdiction, class_name: 'Court::Jurisdiction'
belongs_to :jurisdiction, class_name: 'Court::Jurisdiction', optional: true
belongs_to :municipality

has_many :offices, class_name: 'Court::Office'

belongs_to :information_center, class_name: 'Court::Office'
belongs_to :registry_center, class_name: 'Court::Office'
belongs_to :business_registry_center, class_name: 'Court::Office'
belongs_to :information_center, class_name: 'Court::Office', optional: true
belongs_to :registry_center, class_name: 'Court::Office', optional: true
belongs_to :business_registry_center, class_name: 'Court::Office', optional: true

has_many :expenses, class_name: 'Court::Expense'

Expand Down
9 changes: 5 additions & 4 deletions app/models/decree.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Decree < ActiveRecord::Base
belongs_to :source

belongs_to :proceeding
belongs_to :court
# TODO consider this required in future
belongs_to :proceeding, optional: true
belongs_to :court, optional: true

has_many :judgements
has_many :judges, through: :judgements
Expand All @@ -12,8 +13,8 @@ class Decree < ActiveRecord::Base
has_many :naturalizations, class_name: 'Decree::Naturalization'
has_many :natures, class_name: 'Decree::Nature', through: :naturalizations

belongs_to :legislation_area
belongs_to :legislation_subarea
belongs_to :legislation_area, optional: true
belongs_to :legislation_subarea, optional: true

has_many :legislation_usages
has_many :legislations, through: :legislation_usages
Expand Down
2 changes: 1 addition & 1 deletion app/models/employment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Employment < ActiveRecord::Base
belongs_to :court
belongs_to :judge
belongs_to :judge_position, class_name: 'Judge::Position'
belongs_to :judge_position, class_name: 'Judge::Position', optional: true
end
10 changes: 5 additions & 5 deletions app/models/hearing.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class Hearing < ActiveRecord::Base
belongs_to :source

belongs_to :proceeding
belongs_to :court
belongs_to :proceeding, optional: true
belongs_to :court, optional: true

has_many :judgings
has_many :judges, through: :judgings

belongs_to :type, class_name: 'Hearing::Type', foreign_key: :hearing_type_id
belongs_to :section, class_name: 'Hearing::Section', foreign_key: :hearing_section_id
belongs_to :subject, class_name: 'Hearing::Subject', foreign_key: :hearing_subject_id
belongs_to :form, class_name: 'Hearing::Form', foreign_key: :hearing_form_id
belongs_to :section, class_name: 'Hearing::Section', foreign_key: :hearing_section_id, optional: true
belongs_to :subject, class_name: 'Hearing::Subject', foreign_key: :hearing_subject_id, optional: true
belongs_to :form, class_name: 'Hearing::Form', foreign_key: :hearing_form_id, optional: true

has_many :proposers
has_many :opponents
Expand Down
2 changes: 1 addition & 1 deletion app/models/judge/designation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class Judge::Designation < ActiveRecord::Base
belongs_to :source

belongs_to :judge
belongs_to :type, class_name: 'Judge::Designation::Type', foreign_key: :judge_designation_type_id
belongs_to :type, class_name: 'Judge::Designation::Type', foreign_key: :judge_designation_type_id, optional: true
end
2 changes: 1 addition & 1 deletion app/models/selection_procedure.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SelectionProcedure < ActiveRecord::Base
belongs_to :source

belongs_to :court
belongs_to :court, optional: true

has_many :candidates, class_name: 'SelectionProcedure::Candidate'
has_many :commissioners, class_name: 'SelectionProcedure::Commissioner'
Expand Down
2 changes: 1 addition & 1 deletion app/models/selection_procedure/candidate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SelectionProcedure::Candidate < ActiveRecord::Base
belongs_to :procedure, class_name: 'SelectionProcedure', foreign_key: :selection_procedure_id
belongs_to :judge
belongs_to :judge, optional: true
end
2 changes: 1 addition & 1 deletion app/models/selection_procedure/commissioner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SelectionProcedure::Commissioner < ActiveRecord::Base
belongs_to :procedure, class_name: 'SelectionProcedure', foreign_key: :selection_procedure_id
belongs_to :judge
belongs_to :judge, optional: true
end

0 comments on commit b10617a

Please sign in to comment.