I’ve been working with Rails and legacy databases for a while, but today I’ve hit an error that I could not solve right away:
NoMethodError: undefined method `gteq' for nil:NilClass
All the tests were passing, so it had to be something related to the legacy schema. After googling a lot and not finding anything similar, I delved into Rails source code (thanks RubyMine for making this a lot easier) and finally found the failure: my primary key has a name different than the usual ‘id’. Fixing was damn simple:
class MyRecord < ActiveRecord::Base set_primary_key 'myid' end
Now, back to work!