Remove unnecessary associations
This commit is contained in:
parent
665ccc46fc
commit
a4bd192053
2 changed files with 1 additions and 334 deletions
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RegionalOffice < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
||||
class RegionalOffice < ApplicationRecord
|
||||
################
|
||||
# Associations #
|
||||
################
|
||||
|
@ -11,136 +11,12 @@ class RegionalOffice < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
|||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_many :current_relationships,
|
||||
lambda {
|
||||
select('DISTINCT ON (relationships.person_id) *')
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
},
|
||||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_many :current_supporter_relationships,
|
||||
lambda {
|
||||
select('DISTINCT ON (relationships.person_id) *')
|
||||
.supporters
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
},
|
||||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_many :current_member_relationships,
|
||||
lambda {
|
||||
select('DISTINCT ON (relationships.person_id) *')
|
||||
.members
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
},
|
||||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_many :current_regional_manager_relationships,
|
||||
lambda {
|
||||
select('DISTINCT ON (relationships.person_id) *')
|
||||
.regional_managers
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
},
|
||||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_many :current_regional_supervisor_relationships,
|
||||
lambda {
|
||||
select('DISTINCT ON (relationships.person_id) *')
|
||||
.regional_supervisors
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
},
|
||||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_one :current_regional_secretary_relationship,
|
||||
lambda {
|
||||
select('DISTINCT ON (relationships.person_id) *')
|
||||
.regional_secretaries
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
},
|
||||
class_name: 'Relationship',
|
||||
inverse_of: :regional_office
|
||||
|
||||
has_many :all_people,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :all_relationships,
|
||||
source: :person
|
||||
|
||||
has_many :current_people,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :current_relationships,
|
||||
source: :person
|
||||
|
||||
has_many :current_supporter_people,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :current_supporter_relationships,
|
||||
source: :person
|
||||
|
||||
has_many :current_member_people,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :current_member_relationships,
|
||||
source: :person
|
||||
|
||||
has_many :current_regional_manager_people,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :current_regional_manager_relationships,
|
||||
source: :person
|
||||
|
||||
has_many :current_regional_supervisor_people,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :current_regional_supervisor_relationships,
|
||||
source: :person
|
||||
|
||||
has_one :current_regional_secretary_person,
|
||||
class_name: 'Person',
|
||||
inverse_of: :current_regional_office,
|
||||
through: :current_regional_secretary_relationship,
|
||||
source: :person
|
||||
|
||||
has_many :all_accounts,
|
||||
class_name: 'Account',
|
||||
through: :all_people,
|
||||
source: :account
|
||||
|
||||
has_many :current_accounts,
|
||||
class_name: 'Account',
|
||||
through: :current_people,
|
||||
source: :account
|
||||
|
||||
has_many :current_supporter_accounts,
|
||||
class_name: 'Account',
|
||||
through: :current_supporter_people,
|
||||
source: :account
|
||||
|
||||
has_many :current_member_accounts,
|
||||
class_name: 'Account',
|
||||
through: :current_member_people,
|
||||
source: :account
|
||||
|
||||
has_many :current_regional_manager_accounts,
|
||||
class_name: 'Account',
|
||||
through: :current_regional_manager_people,
|
||||
source: :account
|
||||
|
||||
has_many :current_regional_supervisor_accounts,
|
||||
class_name: 'Account',
|
||||
through: :current_regional_supervisor_people,
|
||||
source: :account
|
||||
|
||||
has_one :current_regional_secretary_account,
|
||||
class_name: 'Account',
|
||||
through: :current_regional_secretary_person,
|
||||
source: :account
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
|
|
@ -27,79 +27,6 @@ RSpec.describe RegionalOffice do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#current_relationships' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_relationships)
|
||||
.class_name('Relationship')
|
||||
.inverse_of(:regional_office)
|
||||
.dependent(:restrict_with_exception)
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_supporter_relationships' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_supporter_relationships)
|
||||
.class_name('Relationship')
|
||||
.inverse_of(:regional_office)
|
||||
.dependent(:restrict_with_exception)
|
||||
.conditions(status: :supporter)
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_member_relationships' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_member_relationships)
|
||||
.class_name('Relationship')
|
||||
.inverse_of(:regional_office)
|
||||
.dependent(:restrict_with_exception)
|
||||
.conditions(status: :member)
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_manager_relationships' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_regional_manager_relationships)
|
||||
.class_name('Relationship')
|
||||
.inverse_of(:regional_office)
|
||||
.dependent(:restrict_with_exception)
|
||||
.conditions(status: :member, role: :regional_manager)
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_supervisor_relationships' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_regional_supervisor_relationships)
|
||||
.class_name('Relationship')
|
||||
.inverse_of(:regional_office)
|
||||
.dependent(:restrict_with_exception)
|
||||
.conditions(status: :member, role: :regional_supervisor)
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_secretary_relationship' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_one(:current_regional_secretary_relationship)
|
||||
.class_name('Relationship')
|
||||
.inverse_of(:regional_office)
|
||||
.dependent(:restrict_with_exception)
|
||||
.conditions(status: :member,
|
||||
role: :regional_manager,
|
||||
regional_secretary_flag: :regional_secretary)
|
||||
.order(person_id: :asc, from_date: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#all_people' do
|
||||
it do
|
||||
is_expected.to \
|
||||
|
@ -110,140 +37,4 @@ RSpec.describe RegionalOffice do
|
|||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_people' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_people)
|
||||
.class_name('Person')
|
||||
.inverse_of(:current_regional_office)
|
||||
.through(:current_relationships)
|
||||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_supporter_people' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_supporter_people)
|
||||
.class_name('Person')
|
||||
.inverse_of(:current_regional_office)
|
||||
.through(:current_supporter_relationships)
|
||||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_member_people' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_member_people)
|
||||
.class_name('Person')
|
||||
.inverse_of(:current_regional_office)
|
||||
.through(:current_member_relationships)
|
||||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_manager_people' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_regional_manager_people)
|
||||
.class_name('Person')
|
||||
.inverse_of(:current_regional_office)
|
||||
.through(:current_regional_manager_relationships)
|
||||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_supervisor_people' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_regional_supervisor_people)
|
||||
.class_name('Person')
|
||||
.inverse_of(:current_regional_office)
|
||||
.through(:current_regional_supervisor_relationships)
|
||||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_secretary_person' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_one(:current_regional_secretary_person)
|
||||
.class_name('Person')
|
||||
.inverse_of(:current_regional_office)
|
||||
.through(:current_regional_secretary_relationship)
|
||||
.source(:person)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#all_accounts' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:all_accounts)
|
||||
.class_name('Account')
|
||||
.through(:all_people)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_accounts' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_accounts)
|
||||
.class_name('Account')
|
||||
.through(:current_people)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_supporter_accounts' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_supporter_accounts)
|
||||
.class_name('Account')
|
||||
.through(:current_supporter_people)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_member_accounts' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_member_accounts)
|
||||
.class_name('Account')
|
||||
.through(:current_member_people)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_manager_accounts' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_regional_manager_accounts)
|
||||
.class_name('Account')
|
||||
.through(:current_regional_manager_people)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_supervisor_accounts' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:current_regional_supervisor_accounts)
|
||||
.class_name('Account')
|
||||
.through(:current_regional_supervisor_people)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_regional_secretary_account' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_one(:current_regional_secretary_account)
|
||||
.class_name('Account')
|
||||
.through(:current_regional_secretary_person)
|
||||
.source(:account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue