Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Dont include the primary key in updates -- its unneeded and SQL Serve…

…r chokes on it

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@42 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9a248a83b5b129ed589f8d829b6ce7316bc1a272 1 parent 005371e
@dhh dhh authored
Showing with 3 additions and 3 deletions.
  1. +3 −3 activerecord/lib/active_record/base.rb
View
6 activerecord/lib/active_record/base.rb
@@ -805,7 +805,7 @@ def create_or_update
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 @@ def remove_attributes_protected_from_mass_assignment(attributes)
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.