Forum: Ruby on Rails Rails add "s" to end of table name with MySQL DB query

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.
jackster (Guest)
on 2006-12-31 01:34
(Received via mailing list)
I'm trying to figure out why my database.yml file is adding the letter
"s" to the name of my table when doing a query.

I tried wiping out my config and starting from scratch using different
file names and table names but it does the exact same thing. For
instance, my table is named "info", when I try to access info from a
web browser, I get a mysql db connection error that says there is no
table named "infos".

Any idea why this is happening?

thanks

john
Jakob S. (Guest)
on 2006-12-31 12:36
(Received via mailing list)
On Dec 20, 2006, at 02:45 , jackster wrote:

> I'm trying to figure out why my database.yml file is adding the letter
> "s" to the name of my table when doing a query.
>
> I tried wiping out my config and starting from scratch using different
> file names and table names but it does the exact same thing. For
> instance, my table is named "info", when I try to access info from a
> web browser, I get a mysql db connection error that says there is no
> table named "infos".
>
> Any idea why this is happening?

Yes, that's what ActiveRecord does by default; pluralized table
names. You can modify this behaviour easily by adding this to your
config/environment.rb:

ActiveRecord::Base.pluralize_table_names = false

--
Jakob S. - http://mentalized.net
RubyGirlUK (Guest)
on 2006-12-31 20:14
jackster wrote:
> I'm trying to figure out why my database.yml file is adding the letter
> "s" to the name of my table when doing a query.
>
> I tried wiping out my config and starting from scratch using different
> file names and table names but it does the exact same thing. For
> instance, my table is named "info", when I try to access info from a
> web browser, I get a mysql db connection error that says there is no
> table named "infos".
>
> Any idea why this is happening?
>
> thanks
>
> john

I think is the way MVC handles the DataBase. Tables map to Classes and
by default Active Recird assumes that the name of a table is a plural
name of the parallel class.
For example Class Shark would become a table name of Sharks.

Hope it helps.
Mike R. (Guest)
on 2006-12-31 20:59
(Received via mailing list)
Hi Jackster,

By default, Rails assumes that a table name is the plural form of the
corresponding model name.  That assumption can be overridden by
uncommenting the line "# ActiveRecord::Base.pluralize_table_names =
false" in your config/environment.rb file.  If you just want to set an
exception for info but pluralize everything else, you can activate and
modify the inflect.uncountable statement which also is commented out in
that same file.

This behavior is described in considerable detail in chapter 14 of the
current Pickaxe book.

-- Mike
This topic is locked and can not be replied to.