@@ -24,8 +24,8 @@ class Organization < ApplicationRecord
2424 has_many :inquiries
2525 has_many :documents , as : :documentable , dependent : :destroy
2626 has_many :petitions , dependent : :delete_all
27- has_many :source_alliances , class_name : "OrganizationAlliance" , foreign_key : "source_organization_id" , dependent : :destroy
28- has_many :target_alliances , class_name : "OrganizationAlliance" , foreign_key : "target_organization_id" , dependent : :destroy
27+ has_many :initiated_alliances , class_name : "OrganizationAlliance" , foreign_key : "source_organization_id" , dependent : :destroy
28+ has_many :received_alliances , class_name : "OrganizationAlliance" , foreign_key : "target_organization_id" , dependent : :destroy
2929
3030 validates :name , presence : true , uniqueness : true
3131
@@ -54,39 +54,30 @@ def display_name_with_uid
5454 self
5555 end
5656
57- # Returns the id to be displayed in the :new transfer page with the given
58- # destination_accountable
59- #
60- # @params destination_accountable [Organization | Object] target of a transfer
61- # @return [Integer | String]
6257 def display_id
6358 account . accountable_id
6459 end
6560
6661 def alliance_with ( organization )
67- source_alliances . find_by ( target_organization : organization ) ||
68- target_alliances . find_by ( source_organization : organization )
62+ initiated_alliances . find_by ( target_organization : organization ) ||
63+ received_alliances . find_by ( source_organization : organization )
6964 end
7065
71- def pending_sent_alliances
72- source_alliances . pending
73- end
74-
75- def pending_received_alliances
76- target_alliances . pending
66+ def pending_alliances
67+ initiated_alliances . pending . or ( received_alliances . pending )
7768 end
7869
7970 def accepted_alliances
80- source_alliances . accepted . or ( target_alliances . accepted )
71+ initiated_alliances . accepted . or ( received_alliances . accepted )
8172 end
8273
8374 def rejected_alliances
84- source_alliances . rejected . or ( target_alliances . rejected )
75+ initiated_alliances . rejected . or ( received_alliances . rejected )
8576 end
8677
8778 def allied_organizations
88- source_org_ids = source_alliances . accepted . pluck ( :target_organization_id )
89- target_org_ids = target_alliances . accepted . pluck ( :source_organization_id )
79+ source_org_ids = initiated_alliances . accepted . pluck ( :target_organization_id )
80+ target_org_ids = received_alliances . accepted . pluck ( :source_organization_id )
9081 Organization . where ( id : source_org_ids + target_org_ids )
9182 end
9283
0 commit comments