From 9a248a83b5b129ed589f8d829b6ce7316bc1a272 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 1 Dec 2004 15:20:53 +0000 Subject: Dont include the primary key in updates -- its unneeded and SQL Server chokes on it git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@42 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3908ea8e4e..8b09c60c53 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -805,7 +805,7 @@ module ActiveRecord #:nodoc: def update connection.update( "UPDATE #{self.class.table_name} " + - "SET #{quoted_comma_pair_list(connection, attributes_with_quotes)} " + + "SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} " + "WHERE #{self.class.primary_key} = '#{id}'", "#{self.class.name} Update" ) @@ -941,10 +941,10 @@ module ActiveRecord #:nodoc: # Returns copy of the attributes hash where all the values have been safely quoted for use in # an SQL statement. - def attributes_with_quotes + def attributes_with_quotes(include_primary_key = true) columns_hash = self.class.columns_hash @attributes.inject({}) do |attrs_quoted, pair| - attrs_quoted[pair.first] = quote(pair.last, columns_hash[pair.first]) + attrs_quoted[pair.first] = quote(pair.last, columns_hash[pair.first]) unless !include_primary_key && pair.first == self.class.primary_key attrs_quoted end end -- cgit v1.2.3