Should Customers and Admins be on Separate Tables?

112 views
Skip to first unread message

Peter

unread,
May 24, 2013, 10:55:53 PM5/24/13
to rubyonra...@googlegroups.com
Can I please get everyone's opinion? Should customers and admins be on separate tables? I'm developing an application that has two kinds of users, a customer and an administrator.

The application basically is a shopping cart. Customers from the internet create their accounts so they are able to buy my products. But there are also administrators (admins). Admins are my employees. They maybe call new customers and try to sell them my products. They have the ability to create, update and manage customers' accounts. Admins are able to buy products for customers upon their request. I hope that makes sense.

Given that admins and customers have different roles but are the same objects, users, should they be in separate tables? Thank you.

cooke...@gmail.com

unread,
May 25, 2013, 1:27:44 AM5/25/13
to rubyonra...@googlegroups.com
I think you should have two separate tables and two controllers. for administrators, you will have more controllers. Many people will put them in a module and add namespace in routes.rb file to visit them.

Colin Law

unread,
May 25, 2013, 2:40:28 AM5/25/13
to rubyonra...@googlegroups.com
On 25 May 2013 03:55, Peter <pe...@poproj.com> wrote:
> Can I please get everyone's opinion? Should customers and admins be on
> separate tables? I'm developing an application that has two kinds of users,
> a customer and an administrator.

You have given the game away here by describing them as 'kinds of
users'. Have one table and distinguish the users types with a
boolean, for example. I guess they will both have to login for
example, and that is much easier with one table. You could look at
the cancan gem to handle the roles but it may be simpler just to use
before_filters to control the access.

>
> The application basically is a shopping cart. Customers from the internet
> create their accounts so they are able to buy my products. But there are
> also administrators (admins). Admins are my employees. They maybe call new
> customers and try to sell them my products. They have the ability to create,
> update and manage customers' accounts. Admins are able to buy products for
> customers upon their request. I hope that makes sense.
>
> Given that admins and customers have different roles but are the same
> objects, users, should they be in separate tables? Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/5f95a7f7-1368-43f3-ac54-18b0dfa64dfb%40googlegroups.com?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Emil S

unread,
May 25, 2013, 11:02:07 AM5/25/13
to rubyonra...@googlegroups.com
In agreement with Colin's point here. If they all log in with the same login form, I'd store them in a single "users" table and have a "roles" field that would help authorize requests using something like "CanCan" .


Himanshu Prakash

unread,
May 27, 2013, 1:15:32 AM5/27/13
to rubyonra...@googlegroups.com
Hi,
Agree to Colin & Emil. I think this is the good opportunity to implement Single Table Inheritance(STI) pattern in your application.
 
-Himanshu

Colin Law

unread,
May 27, 2013, 4:48:14 AM5/27/13
to rubyonra...@googlegroups.com
On 27 May 2013 06:15, Himanshu Prakash <visio...@gmail.com> wrote:
> Hi,
> Agree to Colin & Emil. I think this is the good opportunity to implement
> Single Table Inheritance(STI) pattern in your application.

Generally I think that the additional complication of using STI for a
simple situation such as we have here is not worth the effort. I
would just use a single model. Try it both ways and see which you
like best.

Colin
> https://groups.google.com/d/msgid/rubyonrails-talk/CANQThms2Dvj08LUju2HUCqvEPkbH6uZWXa_%3DHxz%2BjWPD4VuTkA%40mail.gmail.com?hl=en-US.

mike

unread,
May 27, 2013, 11:13:01 AM5/27/13
to rubyonra...@googlegroups.com
I also prefer adding a boolean to the user table, but I can tell you I've seen a lot of cases where separate tables and controllers are created.  I use devise for authentication and the documentation clearly recommends separate tables and controllers.  I've never understood why, I just assumed their needs were more involved than mine, I've always just added the boolean and it's been pretty straightforward. 
Reply all
Reply to author
Forward
0 new messages