From 0c3c131f3b9a82d3e2f36b2930c3437c9f821b6d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 8 Oct 2006 06:45:32 +0000 Subject: The has_many create method works with polymorphic associations. Closes #6361. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5230 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_record/associations/has_many_association.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index d0af68eea7..3cd6e5d716 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -91,20 +91,21 @@ module ActiveRecord @reflection.klass.find(*args) end end - + protected def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) super else + create_scoping = {} + set_belongs_to_association_for(create_scoping) + @reflection.klass.with_scope( + :create => create_scoping, :find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false - }, - :create => { - @reflection.primary_key_name => @owner.id } ) do @reflection.klass.send(method, *args, &block) -- cgit v1.2.3