Skip to content

Commit a364e3c

Browse files
committed
WIP
1 parent 3cf43ea commit a364e3c

File tree

2 files changed

+256
-181
lines changed

2 files changed

+256
-181
lines changed

lib/arel/visitors/sqlserver.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,25 @@ 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
309+
308310
return if o.limit.nil? && o.offset.nil?
309311
return if o.orders.any?
310312

311-
if (projection = projection_to_order_by_for_fetch(o))
313+
314+
315+
if any_groupings?(o) && (projection = projection_to_order_by_for_fetch(o))
312316
o.orders = [projection.asc]
313317
else
314318
pk = primary_Key_From_Table(table_From_Statement(o))
315319
o.orders = [pk.asc] if pk
316320
end
317321
end
318322

323+
def any_groupings?(o)
324+
o.cores.any? { |core| core.groups.present? }
325+
end
326+
319327
# Find the first projection or part of projection that can be used for ordering. Cannot use
320328
# projections with '*' or '1 AS one' in them.
321329
def projection_to_order_by_for_fetch(o)

0 commit comments

Comments
 (0)