From 83c1934003740ed01c618a8943457a0df53e2adb Mon Sep 17 00:00:00 2001 From: mattbauer Date: Sun, 21 Jun 2009 17:35:04 +0100 Subject: Ensure hm:t#create respects source associations hash conditions [#2090 state:resolved] Signed-off-by: Pratik Naik --- .../lib/active_record/associations/through_association_scope.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index 7661c50039..8e7ce33814 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -94,10 +94,17 @@ module ActiveRecord def construct_join_attributes(associate) # TODO: revist this to allow it for deletion, supposing dependent option is supported raise ActiveRecord::HasManyThroughCantAssociateThroughHasManyReflection.new(@owner, @reflection) if @reflection.source_reflection.macro == :has_many + join_attributes = construct_owner_attributes(@reflection.through_reflection).merge(@reflection.source_reflection.primary_key_name => associate.id) + if @reflection.options[:source_type] join_attributes.merge!(@reflection.source_reflection.options[:foreign_type] => associate.class.base_class.name.to_s) end + + if @reflection.through_reflection.options[:conditions].is_a?(Hash) + join_attributes.merge!(@reflection.through_reflection.options[:conditions]) + end + join_attributes end -- cgit v1.2.3