ActiveRecord comments

C

Carl Youngblood

I'm trying out ActiveRecord for the first time and I have a question/suggestion:

I prefer not to pluralize my table names; it's pretty obvious that
they are going to hold more than one row, so why bother? So, in
ActiveRecord, I chose to turn off the default behavior with:

ActiveRecord::Base.pluralize_table_names = false

However, this makes it so I can't declare my objects' associations in
an intuitive way. For example, in the following code:

class Email < ActiveRecord::Base
has_and_belongs_to_many :user
end

I can no longer say has_and_belongs_to_many :users. I have to say
has_and_belongs_to_many :user. When adding multiple associations, I
also can't say someuser.add_emails. I have to say someuser.add_email,
even when I am adding more than one. Why can't I keep my table names
singular and yet refer to my associations in plural form? Since
ActiveRecord already understands plurals, it should be able to reverse
the process as well.

Regardless, it is a great tool that I'm sure will be mighty handy.

Thanks,

Carl Youngblood
 
C

Carl Youngblood

To clarify my thinking on this one, I am suggesting that the
pluralize_table_names option should only change the way ActiveRecord
should look for table names and everything else should be unchanged.
Changing this option should not require the associations to be
declared differently.
 
F

Florian Weber

hello!

i might be wrong, but i think this would work:

has_and_belongs_to_many :users, :class_name => "User"

(you might also need to use the join_table option)

ciao!
florian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top