NoMethodError: undefined method `eq’ for nil:NilClass

JRuby 1.5.2 Rails 3.0 activerecord-jdbc-adapter 0.9.7 This issue arises when setting table name with a schema name prefix. For those in the know – this is a must-have if you’re connecting to oracle using a non-owner username (activerecord-jdbc-adapter). {% highlight ruby %} class Model < ActiveRecord::Base set_table_name ‘.<table>’ end` </table></ts_code> Now – tracking this down led to lib/arel/engines/sql/relations/table.rb `def table_exists? @table_exists ||= @@tables.include?(name) || engine.connection.table_exists?(name) end {% endhighlight %} The `@@tables` include table names as read from the connection (sans schema name). The comparison with the `name` always yields false resulting in an instantiation of an empty Header (with no attributes). Hence – `alias_table[]` always returned nil and nil.eq is undefined. Anyways – as a work around (sorry: non tested monkey patch): in your apps lib folder (provided that it’s auto-loaded) – create the arel\_ext.rb {% highlight ruby %} module Arel class Table def table_exists? #checking with only <table_name> rather than <schema_name>.<table_name> @table_exists ||= @@tables.include?(name.to_s.gsub(/.*\./, ”))|| engine.connection.table_exists?(name) end end end {% endhighlight %} Reported on activerecord-jdbc-adapter list: [http://kenai.com/jira/browse/ACTIVERECORD\_JDBC-132](http://kenai.com/jira/browse/ACTIVERECORD_JDBC-132)

Hey thanks for this, just a heads-up that @@tables no longer works, have to just use tables

I think this might be related to my problem.
Using Rails 3 with MS Sql Server 05.
Legacy tables -> with different names, non auto-incrementing primary key.

Model Code:
class Station < ActiveRecord::Base
self.table_name = “ZDS_SA_STATION”
self.primary_key = “ID_Station”
end

View Code:

And I’m getting the error. I do hope this gets resolved ASAP!

@Omaer – have you tried using set_table_name and set_primary_key instead? Not sure if that would change anything but give it a try.

The issue corresponds to the activerecord-jdbc-adapter which I think is not the same as the adapter you are using. However, that “No Method Error” could be due to a lot of things. Try following your stack trace and see where the source of the issue is.

HTH

@david – thanks for the heads-up