# Repost - Do dynamic finders work with legacy schemas?

**URL:** <https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694>\
**Category:** Rails\
**Created:** [January 6, 2006, 12:00am UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694 "2006-01-06T00:00:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 6, 2006, 12:00am UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/1 "2006-01-06T00:00:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 6, 2006, 1:10am UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/2 "2006-01-06T01:10:06Z")

</div>

On 1/5/06, Eden B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 7, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/3 "2006-01-07T13:37:07Z")

</div>

What does Bug.column\_names return?

- Rowan

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 9, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/4 "2006-01-09T19:50:33Z")

</div>

Rowan,

Thanks for helping me out with this. Bug.column\_names returns and empty  
array [].

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 11, 2006, 6:56pm UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/5 "2006-01-11T18:56:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 11, 2006, 7:30pm UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/6 "2006-01-11T19:30:36Z")

</div>

Using isql to logon to the db, I get 350 rows from “select \* from  
information\_schema.columns”.

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 11, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/7 "2006-01-11T20:25:53Z")

</div>

Clearly your ODBC configuration is working just fine. I think you should  
“Contribute [a] New Ticket” at [http://dev.rubyonrails.org/](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

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 7, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/8 "2006-01-07T13:37:07Z")

</div>

I am connecting to MS SQL server from linux using freeTDS and the ODBC  
layers.

---

<div class="post-metadata">

**Author:** ![Eden\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@Eden\_B](https://www.ruby-forum.com/u/Eden_B)\
**Post date:** [January 12, 2006, 12:29am UTC](https://www.ruby-forum.com/t/repost-do-dynamic-finders-work-with-legacy-schemas/51694/9 "2006-01-12T00:29:26Z")

</div>

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  
(removed\_email\_address@domain.invalid)  
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](http://dev.rubyonrails.org/wiki/ActiveRecord)issue?
