aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-03 22:47:07 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-03 16:24:32 -0800
commit2120da7f733ba33183a42e71256db9652c5f5fcc (patch)
treedc27550f28c65c872d5b5fda8813cacf3746fe1b /activerecord/lib/active_record/relation.rb
parent0619dc2319cf839977ea9670a52d9280a1af3595 (diff)
downloadrails-2120da7f733ba33183a42e71256db9652c5f5fcc.tar.gz
rails-2120da7f733ba33183a42e71256db9652c5f5fcc.tar.bz2
rails-2120da7f733ba33183a42e71256db9652c5f5fcc.zip
ActiveRecord::Relation#primary_key should return a string, just like ActiveRecord::Base.primary_key does.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb19
1 files changed, 6 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 20e983b5f7..1441e9750e 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -10,7 +10,9 @@ module ActiveRecord
include FinderMethods, Calculations, SpawnMethods, QueryMethods, Batches
+ # 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
attr_reader :table, :klass, :loaded
attr_accessor :extensions
@@ -30,13 +32,12 @@ module ActiveRecord
def insert(values)
im = arel.compile_insert values
im.into @table
- primary_key_name = @klass.primary_key
- primary_key_value = primary_key_name && Hash === values ? values[primary_key] : nil
+ primary_key_value = primary_key && Hash === values ? values[table[primary_key]] : nil
@klass.connection.insert(
im.to_sql,
'SQL',
- primary_key_name,
+ primary_key,
primary_key_value)
end
@@ -177,7 +178,7 @@ module ActiveRecord
stmt = arel.compile_update(Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates)))
stmt.take limit
stmt.order(*order)
- stmt.key = @klass.arel_table[@klass.primary_key]
+ stmt.key = table[primary_key]
@klass.connection.update stmt.to_sql
end
end
@@ -320,7 +321,7 @@ module ActiveRecord
# # Delete multiple rows
# Todo.delete([2,3,4])
def delete(id_or_array)
- where(@klass.primary_key => id_or_array).delete_all
+ where(primary_key => id_or_array).delete_all
end
def reload
@@ -336,10 +337,6 @@ module ActiveRecord
self
end
- def primary_key
- @primary_key ||= table[@klass.primary_key]
- end
-
def to_sql
@to_sql ||= arel.to_sql
end
@@ -373,10 +370,6 @@ module ActiveRecord
to_a.inspect
end
- def table_name
- @klass.table_name
- end
-
protected
def method_missing(method, *args, &block)