2018-12-06 17:49:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RegionalOffice < ApplicationRecord
|
2019-03-25 20:56:31 -04:00
|
|
|
################
|
|
|
|
# Associations #
|
|
|
|
################
|
|
|
|
|
2019-06-23 11:59:44 -04:00
|
|
|
belongs_to :federal_subject
|
2018-12-06 17:49:50 -05:00
|
|
|
|
2019-07-20 06:46:49 -04:00
|
|
|
has_many :relationships, inverse_of: :regional_office
|
|
|
|
|
|
|
|
has_many :supporter_relationships,
|
|
|
|
-> { where(status: :supporter) },
|
|
|
|
class_name: 'Relationship',
|
|
|
|
inverse_of: :regional_office
|
|
|
|
|
|
|
|
has_many :member_relationships,
|
|
|
|
-> { where(status: :member) },
|
|
|
|
class_name: 'Relationship',
|
|
|
|
inverse_of: :regional_office
|
2019-04-28 09:06:22 -04:00
|
|
|
|
2019-07-20 06:58:39 -04:00
|
|
|
has_many :manager_relationships,
|
|
|
|
-> { where(status: :member, role: :manager) },
|
|
|
|
class_name: 'Relationship',
|
|
|
|
inverse_of: :regional_office
|
|
|
|
|
|
|
|
has_many :supervisor_relationships,
|
|
|
|
-> { where(status: :member, role: :supervisor) },
|
|
|
|
class_name: 'Relationship',
|
|
|
|
inverse_of: :regional_office
|
|
|
|
|
2019-07-20 05:53:51 -04:00
|
|
|
has_many :people,
|
|
|
|
inverse_of: :regional_office,
|
|
|
|
through: :relationships,
|
2019-07-20 06:25:23 -04:00
|
|
|
source: :person
|
2019-07-20 05:53:51 -04:00
|
|
|
|
2019-07-20 06:46:49 -04:00
|
|
|
has_many :supporter_people,
|
|
|
|
class_name: 'Person',
|
|
|
|
inverse_of: :regional_office,
|
|
|
|
through: :supporter_relationships,
|
|
|
|
source: :person
|
|
|
|
|
|
|
|
has_many :member_people,
|
|
|
|
class_name: 'Person',
|
|
|
|
inverse_of: :regional_office,
|
|
|
|
through: :member_relationships,
|
|
|
|
source: :person
|
|
|
|
|
2019-07-20 06:58:39 -04:00
|
|
|
has_many :manager_people,
|
|
|
|
class_name: 'Person',
|
|
|
|
inverse_of: :regional_office,
|
|
|
|
through: :manager_relationships,
|
|
|
|
source: :person
|
|
|
|
|
|
|
|
has_many :supervisor_people,
|
|
|
|
class_name: 'Person',
|
|
|
|
inverse_of: :regional_office,
|
|
|
|
through: :supervisor_relationships,
|
|
|
|
source: :person
|
|
|
|
|
2019-03-25 20:56:31 -04:00
|
|
|
###############
|
|
|
|
# Validations #
|
|
|
|
###############
|
|
|
|
|
2019-06-23 11:59:44 -04:00
|
|
|
validates :federal_subject, uniqueness: true
|
2018-12-06 17:49:50 -05:00
|
|
|
end
|