Add back options argument in the ActiveRecord::Base.initialize method

This will make easier to hook protected_attributes gem in our code
without making that gem fragile to change in Rails code base.

Closes #12243
上级 a73fd2d3
......@@ -163,7 +163,7 @@ def relation #:nodoc:
# ==== Example:
# # Instantiates a single new object
# User.new(first_name: 'Jamie')
def initialize(attributes = nil)
def initialize(attributes = nil, options = {})
defaults = self.class.column_defaults.dup
defaults.each { |k, v| defaults[k] = v.dup if v.duplicable? }
......@@ -176,7 +176,9 @@ def initialize(attributes = nil)
ensure_proper_type
populate_with_current_scope_attributes
assign_attributes(attributes) if attributes
# +options+ argument is only needed to make protected_attributes gem easier to hook.
# Remove it when we drop support to this gem.
init_attributes(attributes, options) if attributes
yield self if block_given?
run_callbacks :initialize unless _initialize_callbacks.empty?
......@@ -432,5 +434,11 @@ def init_changed_attributes
@changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value, @attributes[attr])
end
end
# This method is needed to make protected_attributes gem easier to hook.
# Remove it when we drop support to this gem.
def init_attributes(attributes, options)
assign_attributes(attributes)
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册