aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/base.rb17
-rw-r--r--activerecord/lib/active_record/relation.rb6
2 files changed, 14 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index a9361f96f0..2157a0aded 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1384,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?
@@ -1416,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
@@ -1808,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
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index dfc66cdd09..062293eea4 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -326,7 +326,11 @@ module ActiveRecord
def scope_for_create
@scope_for_create ||= begin
- @create_with_value || where_values_hash
+ if @create_with_value
+ @create_with_value.reverse_merge(where_values_hash || {})
+ else
+ where_values_hash
+ end
end
end