Skip to content

Commit 6aa1561

Browse files
tenderlovemetaskills
authored andcommitted
call to_i on limit and offset in the visitor
1 parent 95346aa commit 6aa1561

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

lib/arel/visitors/sqlserver.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@ module Nodes
66
class LockWithSQLServer < Arel::Nodes::Unary
77
end
88

9-
# In versions of ActiveRecord prior to v3.0.3 limits and offset were always integers via
10-
# a #to_i. Somewhere between ActiveRecord and ARel this is not happening anymore nor are they
11-
# in agreement which should be responsible. Since we need to make sure that these are visited
12-
# correctly and that we can do math with them, these are here to cast to integers.
13-
class Limit < Arel::Nodes::Unary
14-
def initialize expr
15-
@expr = expr.to_i
16-
end
17-
end
18-
class Offset < Arel::Nodes::Unary
19-
def initialize expr
20-
@expr = expr.to_i
21-
end
22-
end
23-
249
# Extending the Ordering class to be comparrison friendly which allows us to call #uniq on a
2510
# collection of them. See SelectManager#order for more details.
2611
class Ordering < Arel::Nodes::Binary
@@ -166,7 +151,7 @@ def visit_Arel_Nodes_SelectStatementWithOffset(o)
166151

167152
def visit_Arel_Nodes_SelectStatementForComplexCount(o)
168153
core = o.cores.first
169-
o.limit.expr = o.limit.expr + (o.offset ? o.offset.expr : 0) if o.limit
154+
o.limit.expr = o.limit.expr.to_i + (o.offset ? o.offset.expr.to_i : 0) if o.limit
170155
orders = rowtable_orders(o)
171156
[ "SELECT COUNT([count]) AS [count_id]",
172157
"FROM (",

0 commit comments

Comments
 (0)