Skip to content

Commit 3aca4fd

Browse files
committed
Fixes #12: undefined method merge! for conditions with raw sql
1 parent 959f12b commit 3aca4fd

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/polymorphic_integer_type/extensions.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ def remove_type_and_establish_mapping(name, options)
4848
options[:foreign_key] ||= "#{poly_type}_id"
4949
foreign_type = options.delete(:foreign_type) || "#{poly_type}_type"
5050
options[:conditions] ||= {}
51-
options[:conditions].merge!({foreign_type => klass_mapping.to_i})
51+
if options[:conditions].is_a?(Array)
52+
cond = options[:conditions].first
53+
options[:conditions][0] = "(#{cond}) AND #{foreign_type}=#{klass_mapping.to_i}"
54+
else
55+
options[:conditions].merge!({foreign_type => klass_mapping.to_i})
56+
end
5257
end
5358
end
5459

0 commit comments

Comments
 (0)