aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-01-12 21:14:36 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-01-12 21:14:36 +0000
commite24d2f72344baecbcd6fbb76fe3a3171762182e0 (patch)
tree1fce45c301782722656b2aaa5313c4bc0e2207ef /activerecord/lib
parentdd6826eba34769d2af45d45ef91e359cd64eeb00 (diff)
downloadrails-e24d2f72344baecbcd6fbb76fe3a3171762182e0.tar.gz
rails-e24d2f72344baecbcd6fbb76fe3a3171762182e0.tar.bz2
rails-e24d2f72344baecbcd6fbb76fe3a3171762182e0.zip
Apply scoping during initialize instead of create. Fixes setting of foreign key when using find_or_initialize_by with scoping.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5913 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rwxr-xr-xactiverecord/lib/active_record/validations.rb1
2 files changed, 1 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index c51564ecfc..a783feafed 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -447,7 +447,6 @@ module ActiveRecord #:nodoc:
attributes.collect { |attr| create(attr) }
else
object = new(attributes)
- scope(:create).each { |att,value| object.send("#{att}=", value) } if scoped?(:create)
object.save
object
end
@@ -1504,6 +1503,7 @@ module ActiveRecord #:nodoc:
@new_record = true
ensure_proper_type
self.attributes = attributes unless attributes.nil?
+ self.class.send(:scope, :create).each { |att,value| self.send("#{att}=", value) } if self.class.send(:scoped?, :create)
yield self if block_given?
end
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 6f284242cd..b8dc5009ea 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -721,7 +721,6 @@ module ActiveRecord
attributes.collect { |attr| create(attr) }
else
object = new(attributes)
- scope(:create).each { |att,value| object.send("#{att}=", value) } if scoped?(:create)
object.save!
object
end