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
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
See Also: https://github.com/brianhempel/active_record_union/issues/5