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
on 2006-01-06 00:00
on 2006-01-06 01:10
On 1/5/06, Eden Brandeis <firstname.lastname@example.org> 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
on 2006-01-07 13:37
I am connecting to MS SQL server from linux using freeTDS and the ODBC layers.
on 2006-01-07 13:37
What does Bug.column_names return? - Rowan
on 2006-01-09 19:50
Rowan, Thanks for helping me out with this. Bug.column_names returns and empty array [ ].
on 2006-01-11 18:56
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
on 2006-01-11 19:30
Using isql to logon to the db, I get 350 rows from "select * from information_schema.columns".
on 2006-01-11 20:25
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
on 2006-01-12 00:29
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@example.com) 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?