Forum: Ruby on Rails Repost - Do dynamic finders work with legacy schemas?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
61b70c2f195b0e669a8e25000148d9dd?d=identicon&s=25 Eden Brandeis (Guest)
on 2006-01-06 00:00
(Received via mailing list)
Hello everyone,

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.

Any ideas?

Thanks,

Eden
41165a7e7126d616a0ae0762e00718e2?d=identicon&s=25 BigSmoke (Guest)
on 2006-01-06 01:10
(Received via mailing list)
On 1/5/06, Eden Brandeis <ebrandeis@gmail.com> wrote:
>
>  But when I try @bugs = Bug.find(:all, :conditions => ["fOpen = ?", 1]), I
> get the expected find results.
>
>  Any ideas?

May I ask which DBMS you're using (PgSQL, MySQL, Firebird, ...)?

  - Rowan
61b70c2f195b0e669a8e25000148d9dd?d=identicon&s=25 Eden Brandeis (Guest)
on 2006-01-07 13:37
(Received via mailing list)
I am connecting to MS SQL server from linux using freeTDS and the ODBC
layers.
41165a7e7126d616a0ae0762e00718e2?d=identicon&s=25 BigSmoke (Guest)
on 2006-01-07 13:37
(Received via mailing list)
What does Bug.column_names return?

  - Rowan
61b70c2f195b0e669a8e25000148d9dd?d=identicon&s=25 Eden Brandeis (Guest)
on 2006-01-09 19:50
(Received via mailing list)
Rowan,

Thanks for helping me out with this.  Bug.column_names returns and empty
array [ ].
41165a7e7126d616a0ae0762e00718e2?d=identicon&s=25 BigSmoke (Guest)
on 2006-01-11 18:56
(Received via mailing list)
Hi,

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.

  - Rowan
61b70c2f195b0e669a8e25000148d9dd?d=identicon&s=25 Eden Brandeis (Guest)
on 2006-01-11 19:30
(Received via mailing list)
Using isql to logon to the db, I get 350 rows from "select * from
information_schema.columns".
41165a7e7126d616a0ae0762e00718e2?d=identicon&s=25 BigSmoke (Guest)
on 2006-01-11 20:25
(Received via mailing list)
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.

  - Rowan
61b70c2f195b0e669a8e25000148d9dd?d=identicon&s=25 Eden Brandeis (Guest)
on 2006-01-12 00:29
(Received via mailing list)
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
(rails@lists.rubyonrails.org)
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/ActiveRecord>issue?
This topic is locked and can not be replied to.