aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2014-08-05 13:34:57 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2014-08-05 13:34:57 -0300
commit82f6061fbea9bc93c2c254040c53889c33e232c0 (patch)
tree2cdf479f4e96e7789ef57be5c023d00f9b0008fc /activerecord
parentab2a35878b36d005fc9685403342786cffa23700 (diff)
parent977a489cfad70dfd0a6a01c4ef792cf6ac0c9046 (diff)
downloadrails-82f6061fbea9bc93c2c254040c53889c33e232c0.tar.gz
rails-82f6061fbea9bc93c2c254040c53889c33e232c0.tar.bz2
rails-82f6061fbea9bc93c2c254040c53889c33e232c0.zip
Merge pull request #16404 from bogdan/move-create-with-bang
Moved #create! method from Validations to Persistence module
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/persistence.rb12
-rw-r--r--activerecord/lib/active_record/validations.rb15
2 files changed, 12 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 96e44c2f59..f35865f54c 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -36,6 +36,18 @@ module ActiveRecord
end
end
+ # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
+ # so an exception is raised if the record is invalid.
+ def create!(attributes = nil, &block)
+ if attributes.is_a?(Array)
+ attributes.collect { |attr| create!(attr, &block) }
+ else
+ object = new(attributes, &block)
+ object.save!
+ object
+ end
+ end
+
# Given an attributes hash, +instantiate+ returns a new instance of
# the appropriate class. Accepts only keys as strings.
#
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index b4b33804de..7f7d49cdb4 100644
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -29,21 +29,6 @@ module ActiveRecord
extend ActiveSupport::Concern
include ActiveModel::Validations
- module ClassMethods
- # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
- # so an exception is raised if the record is invalid.
- def create!(attributes = nil, &block)
- if attributes.is_a?(Array)
- attributes.collect { |attr| create!(attr, &block) }
- else
- object = new(attributes)
- yield(object) if block_given?
- object.save!
- object
- end
- end
- end
-
# The validation process on save can be skipped by passing <tt>validate: false</tt>.
# The regular Base#save method is replaced with this when the validations
# module is mixed in, which it is by default.