Should Customers and Admins be on Separate Tables?

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.

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.

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” .

Hi,
Agree to Colin & Emil. I think this is the good opportunity to implement
Single Table Inheritance(STI) pattern in your application.

-Himanshu

On 25 May 2013 03:55, Peter [email protected] 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.

On 27 May 2013 06:15, Himanshu P. [email protected] 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

On Friday, May 24, 2013 10:55:53 PM UTC-4, Peter wrote:

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.

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.