Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4645

Show
Ignore:
Timestamp:
08/01/06 03:35:04 (2 years ago)
Author:
bitsweat
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/base.rb

    r4635 r4645  
    17081708      def create_or_update 
    17091709        if new_record? then create else update end 
     1710        true 
    17101711      end 
    17111712 
    17121713      # Updates the associated record with values matching those of the instance attributes. 
     1714      # Returns the number of affected rows. 
    17131715      def update 
    17141716        connection.update( 
     
    17181720          "#{self.class.name} Update" 
    17191721        ) 
    1720          
    1721         return true 
    1722       end 
    1723  
    1724       # Creates a new record with values matching those of the instance attributes. 
     1722      end 
     1723 
     1724      # Creates a record with values matching those of the instance attributes 
     1725      # and returns its id. 
    17251726      def create 
    17261727        if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name) 
    17271728          self.id = connection.next_sequence_value(self.class.sequence_name) 
    17281729        end 
    1729          
     1730 
    17301731        self.id = connection.insert( 
    17311732          "INSERT INTO #{self.class.table_name} " + 
     
    17371738 
    17381739        @new_record = false 
    1739          
    1740         return true 
     1740        id 
    17411741      end 
    17421742