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! -- Posted via http://www.ruby-forum.com/.
On May 11, 2006, at 8:08 AM, Victor Fan wrote:> 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?The table name needs quoting. Active Record does not yet quote table names. jeremy
Jeremy Kemper wrote:> On May 11, 2006, at 8:08 AM, Victor Fan 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. > > jeremyThank you Jeremy Is that mean I have to rename the Products table to products? -- Posted via http://www.ruby-forum.com/.
On May 11, 2006, at 8:43 AM, Victor Fan wrote:> Jeremy Kemper wrote: >> On May 11, 2006, at 8:08 AM, Victor Fan 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?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
I see, thank you so much for your help Jeremy Kemper wrote:> On May 11, 2006, at 8:43 AM, Victor Fan 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-- Posted via http://www.ruby-forum.com/.