jruby/activerecord-jdbc-adapter — Issue #176: ActiveRecord::JDBCError: Invalid column name 'id'
Author: gregors
Created: 2012-02-27 21:59:38+00:00
State: open

I'm working with a legacy windows sql server 2000 database using the jdbcmssql adapter

My model looks like:

class Student < ActiveRecord::Base
self.table_name = "tblSTUDENTS"
self.primary_key = 'StudentKey'

alias_attribute "id", "StudentKey"
end

When I do Student.first or Student.all everything seems to work fine but when I do:
Student.first(10)
Student.limit(10)

I get the following error:

ActiveRecord::JDBCError: Invalid column name 'id'.: SELECT TOP 10 [tblSTUDENTS].* FROM [tblSTUDENTS] WHERE [tblSTUDENTS].id NOT IN (SELECT TOP 0 [tblSTUDENTS].id FROM [tblSTUDENTS] ORDER BY [tblSTUDENTS].StudentKey) ORDER BY [tblSTUDENTS].StudentKey

I'm going to use a view to work around this but in the meantime am I missing something? I'd be glad to dig into the code if someone would give me a starting point.

Thanks
gregors