title: How do I stop these PG::ProtocolViolation errors?
body: <p>My method is:</p>
  
  <pre><code>class Survey &lt; ActiveRecord::Base
    def create_matching_batteries
      unless inactive?
        update_column :battery_id, nil unless battery
        @battery = Battery.where(:review_id =&gt; review.id, :question_id =&gt; question.id).first_or_create
        @battery.surveys &lt;&lt; self
      end
    end
  end
  </code></pre>
  
  <p>When I run <code>@survey.create_matching_batteries</code>, I get this:</p>
  
  <pre><code>Survey Load (5.2ms)  SELECT "surveys".* FROM "surveys" WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1 ORDER BY "surveys"."id" ASC LIMIT 1  [["competitor_id", 248], ["id", 15183]]
  D, [2014-01-21T22:28:08.830446 #3392] DEBUG -- :   Survey Load (5.2ms)  SELECT "surveys".* FROM "surveys" WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1 ORDER BY "surveys"."id" ASC LIMIT 1  [["competitor_id", 248], ["id", 15183]]
  PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1
  : SELECT  "surveys".* FROM "surveys"  WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1  ORDER BY "surveys"."id" ASC LIMIT 1
  E, [2014-01-21T22:28:08.830528 #3392] ERROR -- : PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1
  : SELECT  "surveys".* FROM "surveys"  WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1  ORDER BY "surveys"."id" ASC LIMIT 1
     (0.3ms)  ROLLBACK
  D, [2014-01-21T22:28:08.833655 #3392] DEBUG -- :    (0.3ms)  ROLLBACK
  ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1
  : SELECT  "surveys".* FROM "surveys"  WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1  ORDER BY "surveys"."id" ASC LIMIT 1
  from /Users/steven/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:786:in `get_last_result'
  </code></pre>
  
  <p>In "Railspeak" not "Postgrespeak", what does <code>ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1</code> mean? And how can it help me to debug my method?</p>
  
  <p>My environment:</p>
  
  <pre><code>$ rails -v
  Rails 4.0.2
  $ ruby -v
  ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
  $ psql --version
  psql (PostgreSQL) 9.3.1
  </code></pre>