squeel
squeel copied to clipboard
`bind message supplies 0 parameters, but prepared statement "" requires 1`
While trying to reproduce #343, I ran into another error.
You can use the same repo to reproduce the problem.
has_many :children,
class_name: 'User',
foreign_key: :parent_id,
inverse_of: :parent
belongs_to :parent,
class_name: 'User',
inverse_of: :children
scope :active, ->() { where(active: true) }
def self.x(user)
active_children = user.children.active
joins { active_children.as('active_users').on { id.in(active_users.id) }.outer }
.select { ["users.*", active_users.id.as('calc_active')] }
end
User.create!
User.x(User.first)
# SELECT users.*, "active_users"."id" AS calc_active
# FROM "users" LEFT OUTER JOIN (
# SELECT "users".*
# FROM "users"
# WHERE "users"."parent_id" = $1 AND "users"."active" = 't'
# ) active_users
# ON "users"."id" IN ("active_users"."id")
#
# PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1
Same problem here after updating to rails 4.2.1 - I had no problems with rails 4.1.10
+1 When going from 4.1.16 to 4.2.7.1.
edit: actually, this may not be related to squeel on my end. I'll update later.
Issue is still present on subqueries with polymorphic relations
notes_relation = Person.first.notes
klazz_name = "Person"
relation = Person.joins { notes_relation.as("notes").on { (~id == notes.notable_id) & (notes.notable_type == klazz_name) }.outer }.where { notes.note != nil }
puts relation.debug_sql.inspect
puts relation.to_a
raises: PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 2