Forum: Ruby on Rails When to use Has Many and Has and Belongs to many.

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.
A3c73a768477c8f93dd48d9611376046?d=identicon&s=25 Ron Mr. (rawn027)
on 2007-07-27 19:34
(Received via mailing list)
I am trying to design an interface that handles user accounts and their
email aliases.

What is the relationship between a user and their email accounts?

-Ron
A7f6b372a89349258d08a4d7acb186d4?d=identicon&s=25 Serengeti (Guest)
on 2007-07-27 20:02
(Received via mailing list)
It depends (I know -- great answer).

Do you intend to allow only one e-mail address per user?

If so the email should just be an attribute of your user model (an
email column in the users table).

If you want to allow more than one you could be lazy and just add
columns for email1, email2, and email3.

You could also have a User model and an Email model where User
has_many :emails and Email belongs_to :user.  The emails table would
be pretty simple -- just columns for id and email.

In your controllers you could then use the methods that Rails sets up
for you automatically like:

u = User.find(1)
u.emails
0f0653be00d92cce9db83daccb6de3fb?d=identicon&s=25 cunheise (Guest)
on 2007-07-27 20:12
(Received via mailing list)
sorry i misunderstand does the email aliases is equal to email address
9dfe8c734b0f9b37a4e218425c0a2138?d=identicon&s=25 gene.tani@gmail.com (Guest)
on 2007-07-27 21:05
(Received via mailing list)
On Jul 27, 10:33 am, Ronald Valente <rawn...@gmail.com> wrote:
> I am trying to design an interface that handles user accounts and their
> email aliases.
>
> What is the relationship between a user and their email accounts?
>
> -Ron

this from Apr, 2006, still good orientation material

http://blog.hasmanythrough.com/2006/04/20/many-to-...
This topic is locked and can not be replied to.