Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3, sqlserver, using set_primary_key, and inability to find with a specific ID
    primarykey
    data
    text
    <p>I'm trying to port a Rails2 application over to Rails3 - this app provides a front-end to multiple databases, one of which is SQL Server 2005. The SQL Server 2005 database is legacy so I have to use set_table_name and set_primary_key as such:</p> <pre><code>class Project &lt; ActiveRecord::Base set_table_name "SpiraTest.TST_PROJECT" set_primary_key "PROJECT_ID" end </code></pre> <p>Firing up the console I can see</p> <pre><code>irb(main):002:0&gt; Project.primary_key =&gt; "PROJECT_ID" irb(main):003:0&gt; Project.table_name =&gt; "SpiraTest.TST_PROJECT" irb(main):004:0&gt; </code></pre> <p>I can even use Project.find(:first), Project.find(:last), etc. and retrieve the data. What I can't do is find using an id, like this: Project.find(1). I get met with:</p> <pre><code>NoMethodError: undefined method `eq' for nil:NilClass from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/whiny_nil.rb:48:in `method_missing' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:317:in `find_one' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:292:in `find_with_ids' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:107:in `find' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:444:in `__send__' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:444:in `find' from (irb):4 irb(main):005:0&gt; </code></pre> <p>I have been looking down through the finder_methods and can see where in the find_one method that</p> <pre><code> record = where(primary_key.eq(id)).first </code></pre> <p>'primary_key' is nil.</p> <p>I'm at a loss on this - I'll continue to hunt and see what I find. </p> <p>Gems being used for completeness:</p> <pre><code>gem 'rails', '3.0.9' gem 'mysql2', '&lt; 0.3' gem 'activerecord-sqlserver-adapter' gem 'mongrel' gem 'psrutil' gem 'net-ldap' gem 'spreadsheet' gem 'ruby-odbc' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload