# Model newb qustion

**URL:** <https://www.ruby-forum.com/t/model-newb-qustion/149016>\
**Category:** Rails\
**Created:** [September 19, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/model-newb-qustion/149016 "2008-09-19T12:02:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MCMCMC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@MCMCMC](https://www.ruby-forum.com/u/MCMCMC)\
**Post date:** [September 19, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/model-newb-qustion/149016/1 "2008-09-19T12:02:51Z")

</div>

Just started learning about Rails and I’m trying to figure modeling  
out in my head and I was hoping for some direction. Maybe I am  
thinking too much and have confused myself but I figure if I don’t get  
it right now it may get worse in the future. This is my first attempt  
to create a site:

So I am trying to model users. There are multiple users with different  
access rights. So what is not right in my head is this:

-Do I create one User model and then within the table distingush the  
different users in a field?

or

-Do I create a model for each of the users? (Like: Admin model, Agent  
model, Tutor model, Parent model, Student Model …)

In my model I have agents, tutors, parents, students, and admin.  
Tutors provide services that can be purchased through the site by  
students or parents. The Tutors are signed up to an account by agents.

Which would be right from the following?  
Agents have many tutors  
or should I say  
Agents have many accounts (and then tie the tutor to the account?  
which I guess would then be accounts have one tutor?)

I’m wondering if I just answered my first question about what should  
be a model or not. If an object has associations then is it  
automatically a model?

One of the things that is making me think that there should only be  
the one User model is that if I have a login system and each user  
group sees something different then how does the login controller  
check against multiple different user groups in different models?

Thanks for any help in advance.

MC

---

<div class="post-metadata">

**Author:** ![MCMCMC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@MCMCMC](https://www.ruby-forum.com/u/MCMCMC)\
**Post date:** [September 19, 2008, 2:36pm UTC](https://www.ruby-forum.com/t/model-newb-qustion/149016/2 "2008-09-19T14:36:44Z")

</div>

On Sep 19, 11:13 am, MC [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> different users in a field?  
> Which would be right from the following?  
> the one User model is that if I have a login system and each user  
> group sees something different then how does the login controller  
> check against multiple different user groups in different models?
> 
> Thanks for any help in advance.
> 
> MC

How about having a User and Role model and having them associated with  
each other via a HABTM or a has\_many :through?

---

<div class="post-metadata">

**Author:** ![MCMCMC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@MCMCMC](https://www.ruby-forum.com/u/MCMCMC)\
**Post date:** [September 19, 2008, 2:53pm UTC](https://www.ruby-forum.com/t/model-newb-qustion/149016/3 "2008-09-19T14:53:05Z")

</div>

Why not use Single Table Inheritance where you have a column ‘type’ for  
storing the type of user. Then you will be having a single User model.

I think this might be helpful to you:  
[http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance](http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance)

---

<div class="post-metadata">

**Author:** ![MCMCMC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@MCMCMC](https://www.ruby-forum.com/u/MCMCMC)\
**Post date:** [September 19, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/model-newb-qustion/149016/4 "2008-09-19T17:25:38Z")

</div>

Also in the Book Practical RAils Social Networking Sites the author  
Alan B. works  
through this by using a role model and assigning roles to the users.  
The Administrator then controls who has what role. You might look at  
this method

I am a newb also - so books and forems help alot - Owen

On Sep 19, 5:53 am, ruby rails [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
