# Relationship between Customer, Person, Employee, User entity

**URL:** <https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927>\
**Category:** Rails\
**Created:** [March 29, 2010, 11:43am UTC](https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927 "2010-03-29T11:43:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![paritian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@paritian](https://www.ruby-forum.com/u/paritian)\
**Post date:** [March 29, 2010, 11:43am UTC](https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927/1 "2010-03-29T11:43:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paritian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@paritian](https://www.ruby-forum.com/u/paritian)\
**Post date:** [March 29, 2010, 11:54am UTC](https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927/2 "2010-03-29T11:54:39Z")

</div>

On 29 March 2010 10:43, Paritian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![paritian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@paritian](https://www.ruby-forum.com/u/paritian)\
**Post date:** [March 29, 2010, 11:58am UTC](https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927/3 "2010-03-29T11:58:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paritian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@paritian](https://www.ruby-forum.com/u/paritian)\
**Post date:** [March 29, 2010, 12:23pm UTC](https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927/4 "2010-03-29T12:23:31Z")

</div>

Colin L. 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…

---

<div class="post-metadata">

**Author:** ![paritian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@paritian](https://www.ruby-forum.com/u/paritian)\
**Post date:** [March 29, 2010, 12:47pm UTC](https://www.ruby-forum.com/t/relationship-between-customer-person-employee-user-entity/185927/5 "2010-03-29T12:47:55Z")

</div>

On 29 March 2010 11:23, Paritian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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
