Question

Question title is a bit confusing. I have one class staff and one class project. One or many staffs are working on one or more projects. In this association I have just one link from staff class with * multiplicity to project class with * multiplicity. Now there is another implementation. Each project has only one manager which is in staff class!
My question is, the best way is to have an attribute manager in project class which is foreign key of staff ID or have another link from STAFF class to project class with 1-1 multiplicity? Is it possible to have to links between two class? The final idea is to have an association class between these classes with two field of project manager and project ID?

Was it helpful?

Solution

If a project has a single manager, then an appropriate way to model this is to have a column called ManagerId in the Projects table with an appropriate foreign key reference to another table. If the manager is required, then this would be declared NOT NULL.

If a project could have more than one manager, then you would want an association/junction table to record this information. Doing that when you only want one manager seems like unnecessary complication. And, enforcing constraints on an arbitrary number of things is generally more difficult than just dealing with zero or one.

One exception to the above is when the manager can change over time. Then you would want another table with effective and end dates for the reign of each manager.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top