Paritian Thakkar
2010-Mar-29 09:43 UTC
Relationship between Customer, Person, Employee, User entity
Hello Friends, I am trying to define relationship between real-world entities in my application.... But I am feel, I am over-representing it a little and hence would like your opinion. class User < ActiveRecord::Base has_and_belongs_to_many :user_groups attr_accessible :username, :email, :password, :password_confirmation end class Customer < User has_many :orders belongs_to :person end class Employee < User belongs_to :person end class Person < ActiveRecord::Base has_many :addresses end Should I merge User and Person Models? Basically user has only login information while Person has details like first_name, last_name, address and so on.... Also, should Customer and Employee inherit from Person or User? Trying to normalize stuff but dont want to over-normalize it too.. Thank you. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Mar-29 09:53 UTC
Re: Relationship between Customer, Person, Employee, User entity
On 29 March 2010 10:43, Paritian Thakkar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello Friends, > > I am trying to define relationship between real-world entities in my > application.... But I am feel, I am over-representing it a little and > hence would like your opinion. > > class User < ActiveRecord::Base > has_and_belongs_to_many :user_groups > > attr_accessible :username, :email, :password, :password_confirmation > > end > > class Customer < User > has_many :orders > > belongs_to :person > end > > class Employee < User > belongs_to :person > > end > > class Person < ActiveRecord::Base > has_many :addresses > end > > > Should I merge User and Person Models? Basically user has only login > information while Person has details like first_name, last_name, address > and so on....Yes, why complicate matters. Have you considered that a user might be both a customer and an employee? Your model would preclude that I think. Are you sure it would not be better just to have the user model who can be either or both just by attribute contents? Colin> > Also, should Customer and Employee inherit from Person or User? Trying > to normalize stuff but dont want to over-normalize it too.. > > Thank you. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yong Gu
2010-Mar-29 09:57 UTC
Re: Relationship between Customer, Person, Employee, User entity
I think the differences between Customer and Employee is Role, when you assign a ''customer'' role, he is a customer. So you could use Role to distinguish different person, and a person may have many roles class User < ActiveRecord::Base has_many :roles has_many :addresses end On Mon, Mar 29, 2010 at 5:43 PM, Paritian Thakkar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hello Friends, > > I am trying to define relationship between real-world entities in my > application.... But I am feel, I am over-representing it a little and > hence would like your opinion. > > class User < ActiveRecord::Base > has_and_belongs_to_many :user_groups > > attr_accessible :username, :email, :password, :password_confirmation > > end > > class Customer < User > has_many :orders > > belongs_to :person > end > > class Employee < User > belongs_to :person > > end > > class Person < ActiveRecord::Base > has_many :addresses > end > > > Should I merge User and Person Models? Basically user has only login > information while Person has details like first_name, last_name, address > and so on.... > > Also, should Customer and Employee inherit from Person or User? Trying > to normalize stuff but dont want to over-normalize it too.. > > Thank you. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paritian Thakkar
2010-Mar-29 10:23 UTC
Re: Relationship between Customer, Person, Employee, User entity
Colin Law wrote:> Yes, why complicate matters. > > Have you considered that a user might be both a customer and an > employee? Your model would preclude that I think. Are you sure it > would not be better just to have the user model who can be either or > both just by attribute contents? > > ColinValid point :) I do not want to combine Customer and Employee tables because they have quite different attributes... Employee has department, manager, roles etc... Customer has current status, credit card info etc.. bunch of stuff I will collect on registration.. If I combine them, the resulting table will be a little too huge.. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Mar-29 10:45 UTC
Re: Re: Relationship between Customer, Person, Employee, User entity
On 29 March 2010 11:23, Paritian Thakkar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: > >> Yes, why complicate matters. >> >> Have you considered that a user might be both a customer and an >> employee? Your model would preclude that I think. Are you sure it >> would not be better just to have the user model who can be either or >> both just by attribute contents? >> >> Colin > > Valid point :) > > I do not want to combine Customer and Employee tables because they have > quite different attributes... > > Employee has department, manager, roles etc... > Customer has current status, credit card info etc.. bunch of stuff I > will collect on registration.. If I combine them, the resulting table > will be a little too huge..Assuming you plan to use STI for the tables then the table contains all the attributes for both anyway. Presumably most of the stuff is varchar which are variable length fields. so consume very little space. How many million customers are you expecting so that db size becomes a factor? :) Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.