Hi,
I’m trying to figure out how to model my application. I want to have
two different types of login to the application: Customers and
Administrators. The users are quite different.
Customers are just that and will be associated with orders, carts and
the like. Administrators on the other hand will be used to administer
the site which will include adding, editing, and deleting products,
editing orders, changing statuses etc. At the moment, there’ll only be
a couple of Administrators for the system and it’s likely to stay that
way, but their may be the need for roles to be added in the future so
that each Administrator can have different rights to perform certain
actions.
On the one hand, I don’t like the idea of muddling admins and
customers in the same table. An extra column for specifying the
“admin” role seems a waste for two or three admins vs thousands of
customers. On the other hand, I don’t want to duplicate code. I know I
can reduce this using mixins as quite a lot of the encryption
functions would be the same, but still.
I’ve thought of two options. One, use polymorphic associations:
class Account < ActiveRecord::Base
belongs_to :user, :polymorphic => true
end
class Customer < ActiveRecord::Base
has_one :account, :as => :user
# customer attributes, address and orders associations
end
class Administrator < ActiveRecord::Base
has_one :account, :as => :user
# extra admin attributes
end
Or, two, have separate models and have the code look up the username/
password combos from different database tables. The two user types
wouldn’t know about each other.
Am I mad for separating out the logins? Or, does it make logical sense
based on the fact that the models are filling two completely different
roles.
Any advice gratefully received.
Thanks,
Jordan