Incorrect quoting of primary keys in postgres on insert

151 views
Skip to first unread message

Brendan Billingsley

unread,
Sep 19, 2013, 6:34:34 PM9/19/13
to compos...@googlegroups.com
I've had this problem before, and fixed it before, but I can't figure out what the change is that is preventing this from working this time. When using postgres (postgis) I'm getting an error on insert:
ArgumentError: uncaught throw #<ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "variable_id,dataset_id" does not exist

The insert being run is:
INSERT INTO "citations_contacts" ("citation_id", "contact_id", "role_id", "view_order") VALUES ($1, $2, $3, $4) RETURNING "citation_id,contact_id,role_id"

The issue is the quoting around the primary keys"citation_id,contact_id,role_id" instead of "citation_id","contact_id","role_id". I've tried changing library versions and making other changes to no avail. 

The model file is:
-----------------------------------------------------------------------------------------------
require 'composite_primary_keys'
require 'active_record'
require File.join(File.dirname(__FILE__), 'mixins', 'cloneable')
require File.join(File.dirname(__FILE__), 'mixins', 'creator_fields')

module EdbModel
  class CitationsContact < ActiveRecord::Base
    self.primary_keys = :citation_id, :contact_id, :role_id
    include Cloneable
    include CreatorFields

    belongs_to :citation
    belongs_to :contact
    belongs_to :role

    validates_unique_contact_and_role :citation
  end
end
-----------------------------------------------------------------------------------------------

I'm using composite_primary_keys 5.0.13, pg 0.17 and activerecord-postgis-adapter 0.5.1. Complete Gemfile.lock follows.

I have a very similar setup working from before a refactor we did to introduce namespaces and move the model code into a separate gem. I've tried getting all gem versions identical to that working copy but still can't get this refactored code to work. In addition, the refactored code does work with spatialite, just not with postgres.

Thanks for any assistance, I'm really stumped.

-Brendan

Gemfile.lock:
GEM
  specs:
    actionmailer (3.2.13)
      actionpack (= 3.2.13)
      mail (~> 2.5.3)
    actionpack (3.2.13)
      activemodel (= 3.2.13)
      activesupport (= 3.2.13)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.5)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.2.1)
    activemodel (3.2.13)
      activesupport (= 3.2.13)
      builder (~> 3.0.0)
    activerecord (3.2.13)
      activemodel (= 3.2.13)
      activesupport (= 3.2.13)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activerecord-postgis-adapter (0.6.8)
      rgeo-activerecord (~> 0.5.0)
    activeresource (3.2.13)
      activemodel (= 3.2.13)
      activesupport (= 3.2.13)
    activesupport (3.2.13)
      i18n (= 0.6.1)
      multi_json (~> 1.0)
    acts_as_paranoid (0.4.2)
      activerecord (~> 3.2)
    arel (3.0.2)
    backports (3.3.4)
    builder (3.0.4)
    cancan (1.6.10)
    composite_primary_keys (5.0.13)
      activerecord (~> 3.2.0, >= 3.2.9)
    daemon_controller (1.1.5)
    diff-lcs (1.2.4)
    edb_model (0.5.2)
      activerecord
      activerecord-postgis-adapter
      acts_as_paranoid
      backports
      cancan
      composite_primary_keys (= 5.0.13)
      nokogiri
      pg
      rake-compiler (= 0.8.3)
      rgeo
      rgeo-activerecord
      state_machine (= 1.1.2)
    erubis (2.7.0)
    fastthread (1.0.7)
    hashie (2.0.5)
    hike (1.2.3)
    i18n (0.6.1)
    journey (1.0.4)
    jquery-rails (3.0.4)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    jshint_on_rails (1.0.3)
    json (1.8.0)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    metaclass (0.0.1)
    mime-types (1.25)
    mini_portile (0.5.1)
    mocha (0.14.0)
      metaclass (~> 0.0.1)
    multi_json (1.8.0)
    net-ldap (0.2.2)
    nokogiri (1.6.0)
      mini_portile (~> 0.5.0)
    omniauth (1.1.4)
      hashie (>= 1.2, < 3)
      rack
    omniauth-ldap (1.0.3)
      net-ldap (~> 0.2.2)
      omniauth (~> 1.0)
      pyu-ruby-sasl (~> 0.0.3.1)
      rubyntlm (~> 0.1.1)
    passenger (3.0.19)
      daemon_controller (>= 1.0.0)
      fastthread (>= 1.0.1)
      rack
      rake (>= 0.8.1)
    pg (0.17.0)
    polyglot (0.3.3)
    pyu-ruby-sasl (0.0.3.3)
    rack (1.4.5)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.3)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (3.2.13)
      actionmailer (= 3.2.13)
      actionpack (= 3.2.13)
      activerecord (= 3.2.13)
      activeresource (= 3.2.13)
      activesupport (= 3.2.13)
      bundler (~> 1.0)
      railties (= 3.2.13)
    rails_on_pg (0.2.1)
    railties (3.2.13)
      actionpack (= 3.2.13)
      activesupport (= 3.2.13)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (10.1.0)
    rake-compiler (0.8.3)
      rake
    rdoc (3.12.2)
      json (~> 1.4)
    rgeo (0.3.20)
    rgeo-activerecord (0.5.0)
      activerecord (>= 3.0.3)
      arel (>= 2.0.6)
      rgeo (>= 0.3.20)
    rspec-core (2.14.5)
    rspec-expectations (2.14.2)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-mocks (2.14.3)
    rspec-rails (2.14.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    ruby-prof (0.13.0)
    rubyntlm (0.1.1)
    sprockets (2.2.2)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    state_machine (1.1.2)
    test-unit (2.4.6)
    thor (0.18.1)
    tilt (1.4.1)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.37)
    yard (0.8.7.2)

PLATFORMS
  ruby

DEPENDENCIES
  edb_model
  jquery-rails
  jshint_on_rails
  mocha
  omniauth (>= 1.1.1)
  omniauth-ldap
  passenger (= 3.0.19)
  rails (= 3.2.13)
  rails_on_pg (= 0.2.1)
  rake
  rspec-rails
  ruby-prof
  test-unit (= 2.4.6)
  yard

Brendan Billingsley

unread,
Sep 19, 2013, 7:06:31 PM9/19/13
to compos...@googlegroups.com
I resolved this. My problem was that the composite_primary_keys gem dependency was moved to the gem with our model files. This led to composite_primary_keys not being included until AFTER the database connection was made. This meant the adapter to solve the below problem was not used.

I resolved the problem by adding an explicit require of composite_primary_keys in application.rb. It can also be resolved by adding composite_primary_keys to the Gemfile (rails autoloads everything in that file at boot time).

-Brendan
Reply all
Reply to author
Forward
0 new messages