Forum: Ruby on Rails Legacy database problem

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.
Victor F. (Guest)
on 2006-05-11 19:08
Hi

I am trying to use Ruby on Rails to work with an existing database.  The
problem is that, all the table names begin with a captial letter (e.g.
Products).  So I did the following changes

in environment.rb, I've added under # Include your application
configuration below
ActiveRecord::Base.pluralize_table_names = false

In class Product, I've added
set_table_name "Products"

however, if I try to list all the elements in the Products table
(@products = Product.find(:all)) , I have the following error:
RuntimeError: ERROR	C42P01	Mrelation "products" does not exist
Fnamespace.c	L200	RRangeVarGetRelid: SELECT * FROM Products

but when I create another table with name "products", it worked fine.
Is there any way to solve this problem?

Thank you very much!
Jeremy K. (Guest)
on 2006-05-11 19:35
(Received via mailing list)
On May 11, 2006, at 8:08 AM, Victor F. wrote:
> set_table_name "Products"
>
> however, if I try to list all the elements in the Products table
> (@products = Product.find(:all)) , I have the following error:
> RuntimeError: ERROR	C42P01	Mrelation "products" does not exist
> Fnamespace.c	L200	RRangeVarGetRelid: SELECT * FROM Products
>
> but when I create another table with name "products", it worked fine.
> Is there any way to solve this problem?

The table name needs quoting. Active Record does not yet quote table
names.

jeremy
Victor F. (Guest)
on 2006-05-11 19:43
Jeremy K. wrote:
> On May 11, 2006, at 8:08 AM, Victor F. wrote:
>> set_table_name "Products"
>>
>> however, if I try to list all the elements in the Products table
>> (@products = Product.find(:all)) , I have the following error:
>> RuntimeError: ERROR	C42P01	Mrelation "products" does not exist
>> Fnamespace.c	L200	RRangeVarGetRelid: SELECT * FROM Products
>>
>> but when I create another table with name "products", it worked fine.
>> Is there any way to solve this problem?
>
> The table name needs quoting. Active Record does not yet quote table
> names.
>
> jeremy

Thank you Jeremy

Is that mean I have to rename the Products table to products?
Jeremy K. (Guest)
on 2006-05-11 19:54
(Received via mailing list)
On May 11, 2006, at 8:43 AM, Victor F. wrote:
>>> fine.
>>> Is there any way to solve this problem?
>>
>> The table name needs quoting. Active Record does not yet quote table
>> names.
>>
>> jeremy
>
> Thank you Jeremy
>
> Is that mean I have to rename the Products table to products?

Yes. If you can't rename it, perhaps you have a database that can
provide an alias or synonym (i.e. alias Products to products)

jeremy
Victor F. (Guest)
on 2006-05-11 19:55
I see, thank you so much for your help

Jeremy K. wrote:
> On May 11, 2006, at 8:43 AM, Victor F. wrote:
>>>> fine.
>>>> Is there any way to solve this problem?
>>>
>>> The table name needs quoting. Active Record does not yet quote table
>>> names.
>>>
>>> jeremy
>>
>> Thank you Jeremy
>>
>> Is that mean I have to rename the Products table to products?
>
> Yes. If you can't rename it, perhaps you have a database that can
> provide an alias or synonym (i.e. alias Products to products)
>
> jeremy
This topic is locked and can not be replied to.