activerecord-hackery / squeel

Active Record, improved. Live again :)
http://erniemiller.org/2013/11/17/anyone-interested-in-activerecord-hackery/
MIT License
2.4k stars 213 forks source link

`bind message supplies 0 parameters, but prepared statement "" requires 1` #344

Open shepmaster opened 10 years ago

shepmaster commented 10 years ago

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
marcusg commented 9 years ago

Same problem here after updating to rails 4.2.1 - I had no problems with rails 4.1.10

mchavarriagam commented 7 years ago

+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.

danielnc commented 7 years ago

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