aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorMarcelo Giorgi <marklazz.uy@gmail.com>2010-09-15 12:26:54 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2010-09-28 15:22:50 -0300
commitcdfd013dd7953fc87038c73ecddbaa8cfe29a301 (patch)
treeaec0099a5b67e415c9255c2c63fcb723dd4154dc /activerecord/lib/active_record/base.rb
parent1ef2b47fb12a94f960b34c4bb1e6ad1f9c900e18 (diff)
downloadrails-cdfd013dd7953fc87038c73ecddbaa8cfe29a301.tar.gz
rails-cdfd013dd7953fc87038c73ecddbaa8cfe29a301.tar.bz2
rails-cdfd013dd7953fc87038c73ecddbaa8cfe29a301.zip
Set attributes properly for model built from association with conditions [#5562 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r--activerecord/lib/active_record/base.rb17
1 files changed, 9 insertions, 8 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