ActiveRecord comments

Discussion in 'Ruby' started by Carl Youngblood, Jul 11, 2004.

  1. 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
    Carl Youngblood, Jul 11, 2004
    #1
    1. Advertising

  2. 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.

    On Sat, 10 Jul 2004 21:03:27 -0700, Carl Youngblood
    <> wrote:
    > 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
    >
    Carl Youngblood, Jul 11, 2004
    #2
    1. Advertising

  3. 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



    On Jul 11, 2004, at 6:03 Uhr, Carl Youngblood wrote:

    > 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
    >
    >
    >
    Florian Weber, Jul 11, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,104
  2. Monk
    Replies:
    10
    Views:
    1,448
    Michael Wojcik
    Apr 20, 2005
  3. Devraj

    ActiveRecord for Python/MySQL

    Devraj, Aug 26, 2007, in forum: Python
    Replies:
    3
    Views:
    947
    =?iso-8859-1?q?Luis_M=2E_Gonz=E1lez?=
    Aug 27, 2007
  4. maheshexp
    Replies:
    13
    Views:
    2,047
    ipolevoy
    Jul 23, 2010
  5. Replies:
    4
    Views:
    589
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page