diff options
author | mattbauer <bauer@mmmultiworks.com> | 2009-06-21 17:35:04 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-06-21 17:35:04 +0100 |
commit | 83c1934003740ed01c618a8943457a0df53e2adb (patch) | |
tree | 7822f0bbe20603cc9563e4e59a6a4ba0f5cd71db /activerecord/lib | |
parent | 9cb8c812f2a23ab5653a7888740a014a02c97c18 (diff) | |
download | rails-83c1934003740ed01c618a8943457a0df53e2adb.tar.gz rails-83c1934003740ed01c618a8943457a0df53e2adb.tar.bz2 rails-83c1934003740ed01c618a8943457a0df53e2adb.zip |
Ensure hm:t#create respects source associations hash conditions [#2090 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association_scope.rb | 7 |
1 files changed, 7 insertions, 0 deletions
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 |