aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r--activerecord/lib/active_record/base.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index f5291b180e..2157a0aded 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1014,8 +1014,9 @@ module ActiveRecord #:nodoc:
end
def all_attributes_exists?(attribute_names)
- attribute_names = expand_attribute_names_for_aggregates(attribute_names)
- attribute_names.all? { |name| column_methods_hash.include?(name.to_sym) }
+ expand_attribute_names_for_aggregates(attribute_names).all? { |name|
+ column_methods_hash.include?(name.to_sym)
+ }
end
protected
@@ -1383,10 +1384,7 @@ MSG
ensure_proper_type
- if scope = self.class.send(:current_scoped_methods)
- create_with = scope.scope_for_create
- create_with.each { |att,value| self.send("#{att}=", value) } if create_with
- end
+ populate_with_current_scope_attributes
self.attributes = attributes unless attributes.nil?
result = yield self if block_given?
@@ -1415,10 +1413,7 @@ MSG
@new_record = true
ensure_proper_type
- if scope = self.class.send(:current_scoped_methods)
- create_with = scope.scope_for_create
- create_with.each { |att,value| self.send("#{att}=", value) } if create_with
- end
+ populate_with_current_scope_attributes
end
# Returns a String, which Action Pack uses for constructing an URL to this
@@ -1807,6 +1802,13 @@ MSG
return string unless string.is_a?(String) && string =~ /^---/
YAML::load(string) rescue string
end
+
+ def populate_with_current_scope_attributes
+ if scope = self.class.send(:current_scoped_methods)
+ create_with = scope.scope_for_create
+ create_with.each { |att,value| self.respond_to?(:"#{att}=") && self.send("#{att}=", value) } if create_with
+ end
+ end
end
Base.class_eval do