Skip to content

Commit 10f1d3b

Browse files
committed
WIP
1 parent 72de6cf commit 10f1d3b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lib/arel/visitors/sqlserver.rb

+21-18
Original file line numberDiff line numberDiff line change
@@ -310,33 +310,36 @@ def make_Fetch_Possible_And_Deterministic(o)
310310
return if o.limit.nil? && o.offset.nil?
311311
return if o.orders.any?
312312

313-
314-
315-
if (any_groupings?(o) || xxx_has_join_sources?(o)) && (projection = projection_to_order_by_for_fetch(o))
316-
o.orders = [projection.asc]
317-
else
318-
pk = primary_Key_From_Table(table_From_Statement(o))
319-
o.orders = [pk.asc] if pk
313+
if any_groupings?(o) || has_non_table_join_sources?(o)
314+
if projection = projection_to_order_by_for_fetch(o)
315+
o.orders = [projection.asc]
316+
return
317+
end
320318
end
319+
320+
pk = primary_Key_From_Table(table_From_Statement(o))
321+
o.orders = [pk.asc] if pk
321322
end
322323

323324
def any_groupings?(o)
324325
o.cores.any? { |core| core.groups.present? }
325326
end
326327

328+
def has_non_table_join_sources?(o)
329+
o.cores.none? { |core| core.source.left.is_a?(Arel::Table) }
330+
end
331+
327332
# TODO: Need this for "in the subquery the first projection is used for ordering if none provided" test.
328333
# TODO: rename
329-
def xxx_has_join_sources?(o)
330-
# binding.pry if $DEBUG
331-
332-
333-
return false unless o.is_a?(Arel::Nodes::SelectStatement)
334-
335-
# false
336-
o.cores.any? { |core| core.source.is_a?(Arel::Nodes::JoinSource) }
337-
# rescue => e
338-
# binding.pry
339-
end
334+
# def xxx_has_join_sources?(o)
335+
# # binding.pry if $DEBUG
336+
#
337+
# return true
338+
#
339+
# # return false unless o.is_a?(Arel::Nodes::SelectStatement)
340+
# #
341+
# # o.cores.any? { |core| core.source.is_a?(Arel::Nodes::JoinSource) }
342+
# end
340343

341344
# Find the first projection or part of projection that can be used for ordering. Cannot use
342345
# projections with '*' or '1 AS one' in them.

0 commit comments

Comments
 (0)