diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index a6bbd6f..6f42253 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -32,6 +32,7 @@ rescue LoadError end require 'active_record/base' +require 'active_record/core' require 'active_record/named_scope' require 'active_record/observer' require 'active_record/query_cache' @@ -55,6 +56,7 @@ require 'active_record/dynamic_finder_match' ActiveRecord::Base.class_eval do extend ActiveRecord::QueryCache + include ActiveRecord::Core include ActiveRecord::Validations include ActiveRecord::Locking::Optimistic include ActiveRecord::Locking::Pessimistic diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index bca2db7..d07f52c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2264,9 +2264,9 @@ module ActiveRecord #:nodoc: # before_* callbacks return +false+ the action is cancelled and # +save+ returns +false+. See ActiveRecord::Callbacks for further # details. - def save - create_or_update - end + # def save(*args) + # create_or_update + # end # Saves the model. # diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb new file mode 100644 index 0000000..19d4156 --- /dev/null +++ b/activerecord/lib/active_record/core.rb @@ -0,0 +1,25 @@ +module ActiveRecord + module Core + # :call-seq: + # save(perform_validation = true) + # + # Saves the model. + # + # If the model is new a record gets created in the database, otherwise + # the existing record gets updated. + # + # If +perform_validation+ is true validations run. If any of them fail + # the action is cancelled and +save+ returns +false+. If the flag is + # false validations are bypassed altogether. See + # ActiveRecord::Validations for more information. + # + # There's a series of callbacks associated with +save+. If any of the + # before_* callbacks return +false+ the action is cancelled and + # +save+ returns +false+. See ActiveRecord::Callbacks for further + # details. + def save(*args) + create_or_update + end + + end +end \ No newline at end of file diff --git a/activerecord/lib/active_record/dirty.rb b/activerecord/lib/active_record/dirty.rb index 7e246e6..def0b1d 100644 --- a/activerecord/lib/active_record/dirty.rb +++ b/activerecord/lib/active_record/dirty.rb @@ -37,7 +37,7 @@ module ActiveRecord def self.included(base) base.attribute_method_suffix '_changed?', '_change', '_will_change!', '_was' base.alias_method_chain :write_attribute, :dirty - base.alias_method_chain :save, :dirty + #base.alias_method_chain :save, :dirty base.alias_method_chain :save!, :dirty base.alias_method_chain :update, :dirty base.alias_method_chain :reload, :dirty @@ -71,8 +71,8 @@ module ActiveRecord end # Attempts to +save+ the record and clears changed attributes if successful. - def save_with_dirty(*args) #:nodoc: - if status = save_without_dirty(*args) + def save(*args) #:nodoc: + if status = super(*args) changed_attributes.clear end status diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 970da70..6fa93f3 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -9,7 +9,7 @@ module ActiveRecord base.extend(ClassMethods) base.class_eval do - [:destroy, :save, :save!].each do |method| + [:destroy, :save!].each do |method| alias_method_chain method, :transactions end end @@ -94,8 +94,16 @@ module ActiveRecord with_transaction_returning_status(:destroy_without_transactions) end - def save_with_transactions(perform_validation = true) #:nodoc: - rollback_active_record_state! { with_transaction_returning_status(:save_without_transactions, perform_validation) } + def save(perform_validation = true) #:nodoc: + rollback_active_record_state! { + status = nil + transaction do + status = super #super doesn't play well with send! + raise ActiveRecord::Rollback unless status + end + status + #with_transaction_returning_status(:super, perform_validation) + } end def save_with_transactions! #:nodoc: diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 577e30e..b9ccda2 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -305,7 +305,7 @@ module ActiveRecord def self.included(base) # :nodoc: base.extend ClassMethods base.class_eval do - alias_method_chain :save, :validation + #alias_method_chain :save, :validation alias_method_chain :save!, :validation end @@ -931,9 +931,9 @@ module ActiveRecord # The validation process on save can be skipped by passing false. The regular Base#save method is # replaced with this when the validations module is mixed in, which it is by default. - def save_with_validation(perform_validation = true) + def save(perform_validation = true) if perform_validation && valid? || !perform_validation - save_without_validation + super else false end