@@ -18,23 +18,16 @@ def initialize
18
18
end
19
19
end
20
20
21
- def initialize ( relation , columns = nil , position = nil )
22
- @columns = if columns
23
- Array ( columns )
24
- else
25
- Array ( relation . primary_key ) . map { |pk | "#{ relation . table_name } .#{ pk } " }
26
- end
21
+ def initialize ( relation , columns , position = nil )
22
+ @columns = columns
27
23
self . position = Array . wrap ( position )
28
24
raise ArgumentError , "Must specify at least one column" if columns . empty?
29
- if relation . joins_values . present? && !@columns . all? { |column | column . to_s . include? ( "." ) }
30
- raise ArgumentError , "You need to specify fully-qualified columns if you join a table"
31
- end
32
25
33
26
if relation . arel . orders . present? || relation . arel . taken . present?
34
27
raise ConditionNotSupportedError
35
28
end
36
29
37
- @base_relation = relation . reorder ( @columns . join ( "," ) )
30
+ @base_relation = relation . reorder ( * @columns )
38
31
@reached_end = false
39
32
end
40
33
@@ -54,12 +47,10 @@ def position=(position)
54
47
55
48
def update_from_record ( record )
56
49
self . position = @columns . map do |column |
57
- method = column . to_s . split ( "." ) . last
58
-
59
- if ActiveRecord . version >= Gem ::Version . new ( "7.1.0.alpha" ) && method == "id"
50
+ if ActiveRecord . version >= Gem ::Version . new ( "7.1.0.alpha" ) && column . name == "id"
60
51
record . id_value
61
52
else
62
- record . send ( method . to_sym )
53
+ record . send ( column . name )
63
54
end
64
55
end
65
56
end
@@ -89,14 +80,14 @@ def conditions
89
80
i = @position . size - 1
90
81
column = @columns [ i ]
91
82
conditions = if @columns . size == @position . size
92
- " #{ column } > ?"
83
+ column . gt ( @position [ i ] )
93
84
else
94
- " #{ column } >= ?"
85
+ column . gteq ( @position [ i ] )
95
86
end
96
87
while i > 0
97
88
i -= 1
98
89
column = @columns [ i ]
99
- conditions = " #{ column } > ? OR ( #{ column } = ? AND ( #{ conditions } ))"
90
+ conditions = column . gt ( @position [ i ] ) . or ( column . eq ( @position [ i ] ) . and ( conditions ) )
100
91
end
101
92
ret = @position . reduce ( [ conditions ] ) { |params , value | params << value << value }
102
93
ret . pop
0 commit comments