diff --git a/app/models/regional_office.rb b/app/models/regional_office.rb index 4c1c2aa..61ea946 100644 --- a/app/models/regional_office.rb +++ b/app/models/regional_office.rb @@ -22,7 +22,7 @@ class RegionalOffice < ApplicationRecord has_many :current_supporter_relationships, lambda { select('DISTINCT ON (relationships.person_id) *') - .where(status: :supporter) + .supporters .order(person_id: :asc, from_date: :desc) }, class_name: 'Relationship', @@ -31,7 +31,7 @@ class RegionalOffice < ApplicationRecord has_many :current_member_relationships, lambda { select('DISTINCT ON (relationships.person_id) *') - .where(status: :member) + .members .order(person_id: :asc, from_date: :desc) }, class_name: 'Relationship', @@ -40,7 +40,7 @@ class RegionalOffice < ApplicationRecord has_many :current_regional_manager_relationships, lambda { select('DISTINCT ON (relationships.person_id) *') - .where(status: :member, role: :regional_manager) + .regional_managers .order(person_id: :asc, from_date: :desc) }, class_name: 'Relationship', @@ -49,7 +49,7 @@ class RegionalOffice < ApplicationRecord has_many :current_regional_supervisor_relationships, lambda { select('DISTINCT ON (relationships.person_id) *') - .where(status: :member, role: :regional_supervisor) + .regional_supervisors .order(person_id: :asc, from_date: :desc) }, class_name: 'Relationship', diff --git a/app/models/relationship.rb b/app/models/relationship.rb index 495bf53..ba98edd 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -32,19 +32,21 @@ class Relationship < ApplicationRecord scope :members, -> { where(status: :member) } - scope :federal_managers, -> { where(role: :federal_manager) } + scope :federal_managers, -> { members.where(role: :federal_manager) } - scope :federal_supervisors, -> { where(role: :federal_supervisor) } + scope :federal_supervisors, -> { members.where(role: :federal_supervisor) } - scope :federal_secretaries, - -> { where(federal_secretary_flag: :federal_secretary) } + scope :federal_secretaries, lambda { + federal_managers.where(federal_secretary_flag: :federal_secretary) + } - scope :regional_managers, -> { where(role: :regional_manager) } + scope :regional_managers, -> { members.where(role: :regional_manager) } - scope :regional_supervisors, -> { where(role: :regional_supervisor) } + scope :regional_supervisors, -> { members.where(role: :regional_supervisor) } - scope :regional_secretaries, - -> { where(regional_secretary_flag: :regional_secretary) } + scope :regional_secretaries, lambda { + regional_managers.where(regional_secretary_flag: :regional_secretary) + } ############### # Validations #