Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ActiveRecord comments

Reply
Thread Tools

ActiveRecord comments

 
 
Carl Youngblood
Guest
Posts: n/a
 
      07-11-2004
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


 
Reply With Quote
 
 
 
 
Carl Youngblood
Guest
Posts: n/a
 
      07-11-2004
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
<(E-Mail Removed)> 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
>



 
Reply With Quote
 
 
 
 
Florian Weber
Guest
Posts: n/a
 
      07-11-2004
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
>
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any ActiveRecord implementation for java? maheshexp Java 13 07-23-2010 05:51 AM
ActiveRecord for Python/MySQL Devraj Python 3 08-27-2007 12:23 AM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Javascript 4 06-03-2006 02:00 PM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Java 0 06-02-2006 06:35 AM
Comments format: comments extending over multi-line Monk C Programming 10 04-20-2005 05:09 PM



Advertisments