Issue #180 invalid

collection_singular_ids error from has_many with :through

Anonymous created an issue

Hi,

My model looks like this

class Organization < ActiveRecord::Base has_many :organization_hospitals has_many :hospitals, :through => :organization_hospitals end

When calling

Organization.first.hospital_ids

I get

TypeError: wrong argument type nil (expected String) from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/connection_adapters/postgresql_adapter.rb:1163:in async_exec' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/connection_adapters/postgresql_adapter.rb:1163:inexec_no_cache' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/connection_adapters/postgresql_adapter.rb:660:in block in exec_query' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activesupport-3.2.16/lib/active_support/notifications/instrumenter.rb:20:in instrument' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/connection_adapters/postgresql_adapter.rb:659:in exec_query' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/relation/calculations.rb:184:inpluck' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/associations/collection_association.rb:63:in ids_reader' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/activerecord-3.2.16/lib/active_record/associations/builder/collection_association.rb:62:inblock in define_readers' from (irb):7 from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/railties-3.2.16/lib/rails/commands/console.rb:47:in start' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/railties-3.2.16/lib/rails/commands/console.rb:8:instart' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus/rails.rb:144:in console' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:116:inblock in command' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:103:in fork' ... 7 levels... from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:62:ingo' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:78:in block (3 levels) in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:78:infork' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:78:in block (2 levels) in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:73:ineach' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:73:in block in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:62:inloop' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:62:in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:78:inblock (3 levels) in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:78:in fork' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:78:inblock (2 levels) in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:73:in each' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:73:inblock in go' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:62:in loop' from /home/calin/.rvm/gems/ruby-2.1.0@digital-paper/gems/zeus-0.13.4.pre2/lib/zeus.rb:62:ingo' from -e:1:in `<main>'

Runing rails 3.2.16 on ruby 2.1.0

Comments (3)

  1. Calinoiu Alexandru

    The sql that gets generated is:

    " SELECT COUNT(*)\n FROM pg_class c\n LEFT JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE c.relkind in ('v','r')\n AND c.relname = 'organization_hospitals'\n AND n.nspname = ANY (current_schemas(false))\n" " SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod\n FROM pg_attribute a LEFT JOIN pg_attrdef d\n ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n WHERE a.attrelid = '\"organization_hospitals\"'::regclass\n AND a.attnum > 0 AND NOT a.attisdropped\n ORDER BY a.attnum\n"

  2. Log in to comment