aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2011-03-27 09:54:38 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2011-03-29 17:24:55 +0100
commit555d0163897601010ab1305f41ed393ec517b61e (patch)
treeb6ff36c740894b0c52939bdfe6a0b021a5962235 /activerecord/lib
parenta9dafbb28de3e34c31ebf184fbc4e2042c7ff207 (diff)
downloadrails-555d0163897601010ab1305f41ed393ec517b61e.tar.gz
rails-555d0163897601010ab1305f41ed393ec517b61e.tar.bz2
rails-555d0163897601010ab1305f41ed393ec517b61e.zip
Quote find_in_batches ORDER BY clause [#6620 state:resolved]
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb13
-rw-r--r--activerecord/lib/active_record/relation.rb2
-rw-r--r--activerecord/lib/active_record/relation/batches.rb2
3 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index fcdd31ddea..5f06452247 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -17,6 +17,11 @@ module ActiveRecord
@primary_key ||= reset_primary_key
end
+ # Returns a quoted version of the primary key name, used to construct SQL statements.
+ def quoted_primary_key
+ @quoted_primary_key ||= connection.quote_column_name(primary_key)
+ end
+
def reset_primary_key #:nodoc:
key = self == base_class ? get_primary_key(base_class.name) :
base_class.primary_key
@@ -43,7 +48,12 @@ module ActiveRecord
end
attr_accessor :original_primary_key
- attr_writer :primary_key
+
+ # Attribute writer for the primary key column
+ def primary_key=(value)
+ @quoted_primary_key = nil
+ @primary_key = value
+ end
# Sets the name of the primary key column to use to the given value,
# or (if the value is nil or false) to the value returned by the given
@@ -53,6 +63,7 @@ module ActiveRecord
# set_primary_key "sysid"
# end
def set_primary_key(value = nil, &block)
+ @quoted_primary_key = nil
@primary_key ||= ''
self.original_primary_key = @primary_key
value &&= value.to_s
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 8e545f9cad..896daf516e 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -12,7 +12,7 @@ module ActiveRecord
# These are explicitly delegated to improve performance (avoids method_missing)
delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to => :to_a
- delegate :table_name, :primary_key, :to => :klass
+ delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key, :to => :klass
attr_reader :table, :klass, :loaded
attr_accessor :extensions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index bf5a60f458..d52b84179f 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -83,7 +83,7 @@ module ActiveRecord
private
def batch_order
- "#{table_name}.#{primary_key} ASC"
+ "#{quoted_table_name}.#{quoted_primary_key} ASC"
end
end
end