Forum: Ruby on Rails database and singularity issues

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.
Alan H. (Guest)
on 2009-01-17 08:59
I'm writing my first rails app and following a tutorial to guide me.  I
really like what I see until.... I get to the part where it tells me I
have to follow a certain naming scheme for my database.  Here's my
questions:

1.  Do I HAVE to use plural table names?

I've been designing databases for years.  I understand the logic for
wanting to use plural names, but feel that singular names make more
sense and as such have been designing my databases that way for years.
Is there a workaround?

2.  Do I HAVE to use the id naming standard.

It seems I was taught to name foreign keys with an FK_TableName.  Well,
I hate using underscores in column names.  Also, the FK is lame.  The
naming scheme I use gives each table an primary key named "id".  Any
foreign keys are simply the name of the table which they represent.
(Another reason why I wouldn't want to use plural names).  Is there a
way to implement this in Rails?

3.  Assuming that there are workarounds for these, are they
stable/feasible or would they be a constant nuisance?  Am I better off
to go with the Rails standards?

I appreciate your thoughts.
Frederick C. (Guest)
on 2009-01-17 13:18
(Received via mailing list)
On 17 Jan 2009, at 06:59, Alan Harwood wrote:

> wanting to use plural names, but feel that singular names make more
> sense and as such have been designing my databases that way for years.
> Is there a workaround?

You can set pluralize_table_names on classes (or on ActiveRecord::Base)
> way to implement this in Rails?
>
For foreign keys you can call them whatever you want, but you'll have
to pass :foreign_key => 'blah' to all your associations
If you end up with the association having the same name as the column,
i.e.

belongs_to :person, :foreign_key => 'person'

Then you're definitely skating on thin ice (because the association
accessor methods will overwrite the attribute methods and stuff like
that).

> 3.  Assuming that there are workarounds for these, are they
> stable/feasible or would they be a constant nuisance?  Am I better off
> to go with the Rails standards?
>
Most things can be made to work. I personally wouldn't choose to fight
Rails unless I had to (ie legacy database out of my control)

Fred
This topic is locked and can not be replied to.