Skip to content

Commit 8bf712a

Browse files
rwdbarmintor
authored andcommitted
Prefix column names with model's table name in SQL.
1 parent 88832d2 commit 8bf712a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/oai/provider/model/activerecord_wrapper.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def initialize(model, options={})
3232
end
3333

3434
def earliest
35-
earliest_obj = model.order("#{timestamp_field} asc").first
35+
earliest_obj = model.order("#{model.base_class.table_name}.#{timestamp_field} asc").first
3636
earliest_obj.nil? ? Time.at(0) : earliest_obj.send(timestamp_field)
3737
end
3838

3939
def latest
40-
latest_obj = model.order("#{timestamp_field} desc").first
40+
latest_obj = model.order("#{model.base_class.table_name}.#{timestamp_field} desc").first
4141
latest_obj.nil? ? Time.now : latest_obj.send(timestamp_field)
4242
end
4343
# A model class is expected to provide a method Model.sets that
@@ -137,7 +137,7 @@ def next_set(find_scope, token_string)
137137
def select_partial(find_scope, token)
138138
records = find_scope.where(token_conditions(token))
139139
.limit(@limit)
140-
.order("#{identifier_field} asc")
140+
.order("#{model.base_class.table_name}.#{identifier_field} asc")
141141
raise OAI::ResumptionTokenException.new unless records
142142

143143
total = find_scope.where(token_conditions(token)).count
@@ -158,7 +158,7 @@ def token_conditions(token)
158158

159159
return sql if "0" == last_id
160160
# Now add last id constraint
161-
sql.first << " AND #{identifier_field} > :id"
161+
sql.first << " AND #{model.base_class.table_name}.#{identifier_field} > :id"
162162
sql.last[:id] = last_id
163163

164164
return sql
@@ -169,12 +169,12 @@ def sql_conditions(opts)
169169
sql = []
170170
esc_values = {}
171171
if opts.has_key?(:from)
172-
sql << "#{timestamp_field} >= :from"
172+
sql << "#{model.base_class.table_name}.#{timestamp_field} >= :from"
173173
esc_values[:from] = parse_to_local(opts[:from])
174174
end
175175
if opts.has_key?(:until)
176176
# Handle databases which store fractions of a second by rounding up
177-
sql << "#{timestamp_field} < :until"
177+
sql << "#{model.base_class.table_name}.#{timestamp_field} < :until"
178178
esc_values[:until] = parse_to_local(opts[:until]) { |t| t + 1 }
179179
end
180180

@@ -215,4 +215,3 @@ def parse_to_local(time)
215215

216216
end
217217
end
218-

0 commit comments

Comments
 (0)