ruby - Modelling Company and Person Customers in Rails -


my rails application uses sti have different types of companies , persons. example have suppliers, manufacturers , customers types of company. have employees, contacts , customers types of people.

now want refer customer can either company customer or person customer. method can use/should use combine these 2 different entities one? can refer customer, order?

you either use:

order          belongs_to :company    belongs_to :person end 

and have 2 foreign keys - , add validations make sure 1 of them filled in, , maybe add 'customer' method returns either related company or person, depending used.

or, create separate customer model (and table), has 2 same 2 foreign keys, , order can belong_to :customer. second method may preferably if want store additional data @ customer level (such credit limit, or billing details), , may cleaner long-term.

alternative, reconsider business logic, , insist orders belongs person, if person employee of company , purchasing on behalf of company.

f


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -