What is the best way to model the following…
Assume I have two objects: Agency and Publisher, and both have a 1-to-n relationship to Employee. This is a true 1-to-n relationship, as each Employee can only work for one Agency or one Publisher. Let’s assume further that I cannot introduce a supertype (e.g. Employer) which holds the 1-to-n relationship.
My preferred solution is to have a foreign key in Employee that can either link to a primary key of Agency or Publisher (all my primary keys are 64-bit IDs that are unique across the database). However, now I won’t be able to map a bi-directional association, without indicating in Employee whether this is an Agency or Publisher relationship.
My other option is to use two tables, AgencyEmployee and PublisherEmployee, which can then be linked as traditional 1-to-n bidirectional associations.
What do you consider best practice in this situation?
UPDATE: Thanks for the great responses in such short amount of time! What do you think of the following solution: Foreign keys in Employee for both Agency and Publisher, such as agency_id and publisher_id?
The best practice would probably be introducing an Employer class.
Dividing Employee into AgencyEmployee and PublisherEmployee, on the other hand, would be a Bad Thing™ to do.
If introducing Employer was out of the question, I would indicate the employer type (Agency or Publisher) in Employee.
Response to the updated question:
That is an option, but employer_type is better because: