From 2e455429427a4078d2888cc39305f951bdf1e643 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 12 Aug 2010 21:37:48 -0400 Subject: While creating a new record using has_many create method default scope of child should be respected. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit author.posts.create should take into account default_scope defined on post. [#3939: state:resolved] Signed-off-by: José Valim --- .../lib/active_record/associations/association_collection.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index b5159eead3..132e9cf882 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -492,7 +492,12 @@ module ActiveRecord def create_record(attrs) attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) ensure_owner_is_not_new - record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) do + + _scope = self.construct_scope[:create] + csm = @reflection.klass.send(:current_scoped_methods) + options = (csm.blank? || !_scope.is_a?(Hash)) ? _scope : _scope.merge(csm.where_values_hash) + + record = @reflection.klass.send(:with_scope, :create => options) do @reflection.build_association(attrs) end if block_given? -- cgit v1.2.3