@@ -28,8 +28,6 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
28
28
29
29
# Joins
30
30
LP_LV_JOIN = { Sequel [ :lp ] [ :pact_version_id ] => Sequel [ :lv ] [ :pact_version_id ] }
31
- CONSUMER_JOIN = { Sequel [ :lp ] [ :consumer_id ] => Sequel [ :consumers ] [ :id ] }
32
- PROVIDER_JOIN = { Sequel [ :lp ] [ :provider_id ] => Sequel [ :providers ] [ :id ] }
33
31
CONSUMER_VERSION_JOIN = { Sequel [ :lp ] [ :consumer_version_id ] => Sequel [ :cv ] [ :id ] }
34
32
PROVIDER_VERSION_JOIN = { Sequel [ :lv ] [ :provider_version_id ] => Sequel [ :pv ] [ :id ] }
35
33
@@ -63,11 +61,11 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
63
61
]
64
62
ALL_COLUMNS = CONSUMER_COLUMNS + CONSUMER_VERSION_COLUMNS + PACT_COLUMNS +
65
63
PROVIDER_COLUMNS + PROVIDER_VERSION_COLUMNS + VERIFICATION_COLUMNS
66
- PACTICIPANT_NAMES_AND_IDS = CONSUMER_COLUMNS + PROVIDER_COLUMNS
64
+
67
65
68
66
# cachable select arguments
69
67
SELECT_ALL_COLUMN_ARGS = [ :select_all_columns ] + ALL_COLUMNS
70
- SELECT_PACTICIPANT_NAMES_AND_IDS_ARGS = [ :select_pacticipant_names_and_ids ] + PACTICIPANT_NAMES_AND_IDS
68
+ SELECT_PACTICIPANT_IDS_ARGS = [ :select_pacticipant_ids , Sequel [ :lp ] [ :consumer_id ] , Sequel [ :lp ] [ :provider_id ] ]
71
69
72
70
associate ( :many_to_one , :pact_publication , :class => "PactBroker::Pacts::PactPublication" , :key => :pact_publication_id , :primary_key => :id )
73
71
associate ( :many_to_one , :provider , :class => "PactBroker::Domain::Pacticipant" , :key => :provider_id , :primary_key => :id )
@@ -83,12 +81,21 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
83
81
include PactBroker ::Repositories ::Helpers
84
82
85
83
select *SELECT_ALL_COLUMN_ARGS
86
- select *SELECT_PACTICIPANT_NAMES_AND_IDS_ARGS
84
+ select *SELECT_PACTICIPANT_IDS_ARGS
87
85
88
86
def distinct_integrations selectors
89
- select_pacticipant_names_and_ids
87
+ select_pacticipant_ids
90
88
. distinct
91
89
. matching_selectors ( selectors )
90
+ . from_self ( alias : :pacticipant_ids )
91
+ . select (
92
+ :consumer_id ,
93
+ Sequel [ :c ] [ :name ] . as ( :consumer_name ) ,
94
+ :provider_id ,
95
+ Sequel [ :p ] [ :name ] . as ( :provider_name )
96
+ )
97
+ . join_consumers ( :pacticipant_ids , :c )
98
+ . join_providers ( :pacticipant_ids , :p )
92
99
end
93
100
94
101
def matching_selectors selectors
@@ -179,12 +186,20 @@ def join_pacticipants_and_pacticipant_versions
179
186
. join_provider_versions
180
187
end
181
188
182
- def join_consumers
183
- join ( :pacticipants , CONSUMER_JOIN , { table_alias : :consumers } )
189
+ def join_consumers qualifier = :lp , table_alias = :consumers
190
+ join (
191
+ :pacticipants ,
192
+ { Sequel [ qualifier ] [ :consumer_id ] => Sequel [ table_alias ] [ :id ] } ,
193
+ { table_alias : table_alias }
194
+ )
184
195
end
185
196
186
- def join_providers
187
- join ( :pacticipants , PROVIDER_JOIN , { table_alias : :providers } )
197
+ def join_providers qualifier = :lp , table_alias = :providers
198
+ join (
199
+ :pacticipants ,
200
+ { Sequel [ qualifier ] [ :provider_id ] => Sequel [ table_alias ] [ :id ] } ,
201
+ { table_alias : table_alias }
202
+ )
188
203
end
189
204
190
205
def join_consumer_versions
0 commit comments