I have something bother me in the understanding of polymorphism (vs role):
Note: I am using rails (but it's a general question)
I have 4 models:
There is a polymorphic association (profileable) between Pro/Customer and User [because Pro has many more fields for the registration process than Customer].
User is used for the session (I am using the devise gem)
Basically something very similar to this writing is used:
- Now, I want to create my association with Company.
- By now, only Pro has one Company (but I figure it could be other profileable_type which can also have a Company).
- Customer doesn't have a Company.
In that case which association is preferable:
- User has_one Company
- Company belongs_to User
- and manage authorization (with a gem like cancan) to permit company creation only for Pro (with my profileable_type field in the user table)
- Pro has_one Company
- Company belongs_to Pro
- So in that case I don't need any authorization management anymore (User (and by extension Customer) cannot create company by default)
Looking for pros/cons of the 2 approaches. I am pretty sure the first one is the best solution as I have a user_id in my company table which would be more generic and expandable than having a pro_id.. I would be pleased to be sure. Thanks!