S
S
StanisLove2015-09-03 09:09:06
Ruby on Rails
StanisLove, 2015-09-03 09:09:06

User model with role attribute or separate models?

Good afternoon!
The user can be either a seller or a buyer.
Better:
User model with attribute role: "seller" || "buyer"
or
Individual models Seller, Buyer ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TyzhSysAdmin, 2015-09-03
@POS_troi

UserGroup(many) -> User(belongs)

K
Konstantin T, 2015-09-03
@RooTooZ

If the task remains only on this, then you can generally make a boolean field of the seller type , and call the seller in the context of the program ? to check who is the buyer or seller .
But this is if you do not appear in the future, for example, even the role of a manager or consultant! Then this approach is not logical. Then it is better to refer to the answer of Alexey POS_troi , he showed a method where roles are stored in a separate model, and the user has a binding to this role.
When designing a database and (or) a model, you need to look forward a little.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question