O.K. I’ve been working with Rails for several weeks now and am loving the ease for cranking out websites. Good stuff.
But…
(and that’s a big butt)
For some insane reason the developers of Rails decided plural table names was a convention worth promoting by having it as the default.
Most experienced DBAs will tell you that the name of a table should describe what one record in that table would represent. Who would recommend plural table names? Developers seem to like plural names because they equate database tables with Collections (think java.util.List). I guess I come from a more traditional background where I think of tables as set theory.
Naming guidelines aside there is another reason not to go down this route. Rails then has to be smart enough to parse the plurals for almost every noun in the English dictionary.
What short-circuited in the developer’s brains? They develop this slick environment and then slap in some hacky idea. I think it is only useful to add to the perceived “wow” factor that the Rails enthusiasts get at conferences. yee-ha!
Luckily there is a work-around to make Rails work just as nicely with singular table names.
Thanks to this post on justinram.wordpress.com for providing the answer on how to switch off this really stupid bug in rails:
Add the following to the bottom of your config/environment.rb file:
# Include your application configuration below
ActiveRecord::Base.pluralize_table_names = false
Design by convention
Final thing that “really grinds my gears” (Family Guy) is that it goes against the grain of “design by convention” that is Rails major contribution to the web space. Why would all my controllers, views, helpers, etc be called Employee and my table name be Employees?
Why would my code refer to “Sheep” and my table name be “Sheep”. Well, maybe that wasn’t a good example.
I guess in the end there is a difference between convention magic: “Hey, all my MVC objects are named the same so I don’t have to configure them - that makes sense” and spooky “under the covers” magic “Hey I magically figured out that your Alumnus class should be related to the Alumni table”
It is a good thing that Rails has that call to the Dictionary.com web service to get the plural name for every model.