It appears to me that being a customer or a vendor is a property of company. Therefore, you could just have a field in the company table called something like 'relationship' with possible entries of 'customer' and 'vendor'. Then to get all customers, you'd simply use:
Code:
Company.find_all_by_relationship('customer')
If it is that simple, then job done, short of adding some validation tasks and control to ensure only the correct entries of 'customer' or 'vendor' appear in the relationship field.
The problems arise if you have a company that is both a customer and a vendor. Also what do you do if you need to add a new relationship: for example 'partner' or 'competitor'.
Therefore, if the simple solution above won't work for you, I think the best scalable option would be to add a relationships table to store and define the types of relationship. You could then use has_to_and_belongs_to_many to join the tables via a companies_relationships join table. You could then find customers via:
Code:
Relationship.find_by_name("customer").companies
Bookmarks