From e24d2f72344baecbcd6fbb76fe3a3171762182e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Fri, 12 Jan 2007 21:14:36 +0000 Subject: 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 --- activerecord/lib/active_record/base.rb | 2 +- activerecord/lib/active_record/validations.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3