jackc / surus

PostgreSQL extensions for ActiveRecord
MIT License
395 stars 35 forks source link

Correction prepared statements #17

Closed mathieumahe closed 9 years ago

mathieumahe commented 9 years ago

When working with nested models, activerecord can use prepared statements like the following :

$> Cursus.find(1).projects.to_sql
=> "SELECT \"projects\".* FROM \"projects\" INNER JOIN \"cursus_projects\" ON \"projects\".\"id\" = \"cursus_projects\".\"project_id\" WHERE \"cursus_projects\".\"cursus_id\" = $1" #(note the $1)

When coupling with all_json, it creates an PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1 error.

Replace to_sql by to_sql_with_binding_params fixes the problem.

jackc commented 9 years ago

Thanks!