diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-10-06 00:49:58 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-10-06 00:49:58 +0000 |
commit | 638505b90f593c8ee48a060f378ed6a9c93442e1 (patch) | |
tree | 6a4e7ecf398429d16ec58e515255f2f43fa6baa4 /activerecord/lib/active_record/base.rb | |
parent | 4db718e2bb514be7a2e76e56cb5027c4007528b4 (diff) | |
download | rails-638505b90f593c8ee48a060f378ed6a9c93442e1.tar.gz rails-638505b90f593c8ee48a060f378ed6a9c93442e1.tar.bz2 rails-638505b90f593c8ee48a060f378ed6a9c93442e1.zip |
Send the correct INSERT statement when dealing with objects with only primary keys. Closes #9523 [tarmo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7753 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5e1185065e..068d9a5c45 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1968,9 +1968,11 @@ module ActiveRecord #:nodoc: # Updates the associated record with values matching those of the instance attributes. # Returns the number of affected rows. def update + quoted_attributes = attributes_with_quotes(false, false) + return 0 if quoted_attributes.empty? connection.update( "UPDATE #{self.class.table_name} " + - "SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false))} " + + "SET #{quoted_comma_pair_list(connection, quoted_attributes)} " + "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", "#{self.class.name} Update" ) @@ -1983,13 +1985,18 @@ module ActiveRecord #:nodoc: self.id = connection.next_sequence_value(self.class.sequence_name) end - self.id = connection.insert( + quoted_attributes = attributes_with_quotes + + statement = if quoted_attributes.empty? + connection.empty_insert_statement(self.class.table_name) + else "INSERT INTO #{self.class.table_name} " + "(#{quoted_column_names.join(', ')}) " + - "VALUES(#{attributes_with_quotes.values.join(', ')})", - "#{self.class.name} Create", - self.class.primary_key, self.id, self.class.sequence_name - ) + "VALUES(#{quoted_attributes.values.join(', ')})" + end + + self.id = connection.insert(statement, "#{self.class.name} Create", + self.class.primary_key, self.id, self.class.sequence_name) @new_record = false id |