brianhempel / active_record_union

UNIONs in ActiveRecord! Adds proper union and union_all methods to ActiveRecord::Relation.
Other
423 stars 41 forks source link

Fixed Issue with polymorphic relations #7

Closed efradelos closed 8 years ago

efradelos commented 8 years ago

Addresses an issue where doing a union with polymorphic relationships fails with error:

ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 2

Steps to reproduce

class Picture < ActiveRecord::Base
  belongs_to :imageable, polymorphic: true
end

class Employee < ActiveRecord::Base
  has_many :pictures, as: :imageable
end

class Product < ActiveRecord::Base
  has_many :pictures, as: :imageable
end

Employee.joins(:pictures).select(:name).union(Product.joins(:pictures).select(:name))  <--- fails

See Also: https://github.com/brianhempel/active_record_union/issues/5

brianhempel commented 8 years ago

Thanks for the PR! It fixed the bug. I've merged this.

v1.1.1 is live on RubyGems with this fix.