File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -305,14 +305,14 @@ def select_statement_lock?
305305 # FETCH cannot be used without an order. If an order is not given then try to use the projections for the ordering.
306306 # If no suitable projection are present then fallback to using the primary key of the table.
307307 def make_Fetch_Possible_And_Deterministic ( o )
308- binding . pry if $DEBUG
308+ # binding.pry if $DEBUG
309309
310310 return if o . limit . nil? && o . offset . nil?
311311 return if o . orders . any?
312312
313313
314314
315- if any_groupings? ( o ) && ( projection = projection_to_order_by_for_fetch ( o ) )
315+ if ( any_groupings? ( o ) || has_join_sources? ( o ) ) && ( projection = projection_to_order_by_for_fetch ( o ) )
316316 o . orders = [ projection . asc ]
317317 else
318318 pk = primary_Key_From_Table ( table_From_Statement ( o ) )
@@ -324,6 +324,19 @@ def any_groupings?(o)
324324 o . cores . any? { |core | core . groups . present? }
325325 end
326326
327+ # TODO: Need this for "in the subquery the first projection is used for ordering if none provided" test.
328+ def has_join_sources? ( o )
329+ # binding.pry if $DEBUG
330+
331+
332+ return false unless o . is_a? ( Arel ::Nodes ::SelectStatement )
333+
334+ # false
335+ o . cores . any? { |core | core . source . is_a? ( Arel ::Nodes ::JoinSource ) }
336+ rescue => e
337+ binding . pry
338+ end
339+
327340 # Find the first projection or part of projection that can be used for ordering. Cannot use
328341 # projections with '*' or '1 AS one' in them.
329342 def projection_to_order_by_for_fetch ( o )
You can’t perform that action at this time.
0 commit comments