I have another question related to a legacy schema I am working with.
Do dynamic finders work with legacy schemas in general? The schema I am
working with uses hungarian prefixes for column names. For example
fOpen is
0 if a bug is closed and 1 if it is open (type smallint). When I try @bugs
= Bug.find_all_by_fOpen(1), I get the following exception:
undefined method `find_by_fOpen’ for Bug:Class
But when I try @bugs = Bug.find(:all, :conditions => [“fOpen = ?”, 1]),
I
get the expected find results.
I suspect that your problem is caused by a bug or a misconfiguration in
your
ODBC driver or by a bug in the ActiveRecord adapter for ODBC.
Does the user as which you’re connecting to the MS SQL server have
access to
the information_schema? You could test this by connecting to it as that
user
using an ODBC test program and issuing “select * from
information_schema.columns”. If it happens that you can’t get it, AR
won’t
get it. I’m not even sure if it is possible to restrict acces to the
information_schema, but I’m having trouble coming up with a logical
reason.
Perhaps an AR developer can chip in and make a wild guess at why
Model.column_names wouldn’t return anything while raw queries do? To me
it
sounds as if AR either doesn’t try or doesn’t succeed in reading the
information_schema.
Clearly your ODBC configuration is working just fine. I think you should
“Contribute [a] New Ticket” at http://dev.rubyonrails.org/
This has all the looks of an Active Record issue. I think it’s a good
idea
to refer to this thread for clarification and perhaps post a link to the
new
ticket in this thread.
Thanks again for your help. I created the following ticket as
suggested:
Ticket #3452 (defect)
Opened 1 second ago
Dynamic finders not working with legacy database Status: new
Reported
by: ebrandeis Assigned to: David Priority: normal Milestone:
Component: ActiveRecord Version: 1.0.0 Severity: normal Keywords:
dynamic
finder legacy schema Cc:
I am using freeTDS and ODBC on FC4 to access a legacy MSSQL server DB.
The
schema I am working with uses hungarian prefixes for column names. For
example fOpen is 0 if a bug is closed and 1 if it is open (type
smallint).
When I try @bugs = Bug.find_all_by_fOpen(1), I get the following
exception:
undefined method `find_by_fOpen’ for Bug:Class
But when I try @bugs = Bug.find(:all, :conditions => [“fOpen = ?”, 1]),
I
get the expected find results.
I raised this issue on the rails mailing list
([email protected])
under the thread “Repost - Do dynamic finders work with legacy
schemas?”.
One reader (Rowan) had me check Bug.column_names and I found that it
returns
an empty array []. I tried the query “select * from
information_schema.columns” using isql and got 350 rows, so it seems my
DB
connection configuration is correct. Is this an
ActiveRecord?http://dev.rubyonrails.org/wiki/ActiveRecordissue?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.