diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-01 03:35:04 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-01 03:35:04 +0000 |
commit | 9ee5d54e4db5d8448d643fbeece6d42cc7179c7a (patch) | |
tree | a2d2eb9c74a49745518e7214d07468466551bfd4 /activerecord | |
parent | 58b996f9b03668573fef2696d583ff04191a5fa7 (diff) | |
download | rails-9ee5d54e4db5d8448d643fbeece6d42cc7179c7a.tar.gz rails-9ee5d54e4db5d8448d643fbeece6d42cc7179c7a.tar.bz2 rails-9ee5d54e4db5d8448d643fbeece6d42cc7179c7a.zip |
r4889@ks: jeremy | 2006-07-31 20:27:15 -0700
Create and update return the new pk and the number of affected rows, respectively. The job of returning true to appease the validations chain is up to create_or_update.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4645 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e90c65ee07..52b7df7fe8 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1707,9 +1707,11 @@ module ActiveRecord #:nodoc: private def create_or_update if new_record? then create else update end + true end # Updates the associated record with values matching those of the instance attributes. + # Returns the number of affected rows. def update connection.update( "UPDATE #{self.class.table_name} " + @@ -1717,16 +1719,15 @@ module ActiveRecord #:nodoc: "WHERE #{self.class.primary_key} = #{quote(id)}", "#{self.class.name} Update" ) - - return true end - # Creates a new record with values matching those of the instance attributes. + # Creates a record with values matching those of the instance attributes + # and returns its id. def create if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name) self.id = connection.next_sequence_value(self.class.sequence_name) end - + self.id = connection.insert( "INSERT INTO #{self.class.table_name} " + "(#{quoted_column_names.join(', ')}) " + @@ -1736,8 +1737,7 @@ module ActiveRecord #:nodoc: ) @new_record = false - - return true + id end # Sets the attribute used for single table inheritance to this class name if this is not the ActiveRecord descendent. |