Posts NoMethodError: undefined method `eq’ for nil:NilClass
Post
Cancel

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).

class Model < ActiveRecord::Base
  set_table_name '<schema>.<table>'
end`
</table></schema></ts_code><!-- [Format Time: 0.0126 seconds] --> Now – tracking this down led to lib/arel/engines/sql/relations/table.rb <!-- Crayon Syntax Highlighter v1.13.1 --><ts_code>`def table_exists?
  @table_exists ||= @@tables.include?(name) || engine.connection.table_exists?(name)
end

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[<attr>] 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

module Arel
  class Table
    def table_exists?
     #checking with only &lt;table_name&gt; rather than &lt;schema_name&gt;.&lt;table_name&gt;

      @table_exists ||= @@tables.include?(name.to_s.gsub(/.*\./, ''))|| engine.connection.table_exists?(name)
    end
  end
end

Reported on activerecord-jdbc-adapter list: 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

Contents

Search Results