@@ -24,8 +24,8 @@ class Organization < ApplicationRecord
24
24
has_many :inquiries
25
25
has_many :documents , as : :documentable , dependent : :destroy
26
26
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
29
29
30
30
validates :name , presence : true , uniqueness : true
31
31
@@ -54,39 +54,30 @@ def display_name_with_uid
54
54
self
55
55
end
56
56
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]
62
57
def display_id
63
58
account . accountable_id
64
59
end
65
60
66
61
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 )
69
64
end
70
65
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 )
77
68
end
78
69
79
70
def accepted_alliances
80
- source_alliances . accepted . or ( target_alliances . accepted )
71
+ initiated_alliances . accepted . or ( received_alliances . accepted )
81
72
end
82
73
83
74
def rejected_alliances
84
- source_alliances . rejected . or ( target_alliances . rejected )
75
+ initiated_alliances . rejected . or ( received_alliances . rejected )
85
76
end
86
77
87
78
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 )
90
81
Organization . where ( id : source_org_ids + target_org_ids )
91
82
end
92
83
0 commit comments