|
1 2 3 |
class Model < ActiveRecord::Base
set_table_name '<schema>.<table>'
end |
|
1 2 3 |
def table_exists?
@table_exists ||= @@tables.include?(name) || engine.connection.table_exists?(name)
end |
@@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
|
1 2 3 4 5 6 7 8 |
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 |
4 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
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