views:

77

answers:

4

How do I model any additional properties from One-Many relationships in the database back into classes?

For example I have 3 tables Model, Manager and Model_Manager. The Model_Manager table has ModelId, ManagerId and two extra properties - Percentage and Owner.

At first I created two classes Manager and Model and the Model class contains a collection of Managers to capture the 1-Many link.

But now where do I put the additional Percentage and Owner properties. Does it make sense to actually have a Model_Manager class in the design even if it's not a "real-business" class?

+2  A: 

This is a many-to-many-relationship with extra data. This is typically modeled as two one-to-many relationships. So yes, you do need to have a Model_Manager class, though you might consider a better name (ManagedModel?). Model and Manager each have a one-to-many relationship with Model_Manager.

Jamie Ide
A: 

Well, presumably every Manager has a set of Models that it can manage a percentage of, so...

I would create a ManagedModel class that contains a pointer to a Model object and the additional properties. Then each Manager could have a set of ManagedModel objects.

sangretu
+1  A: 

It sounds like your additional 2 properties are link attributes and should therefore be represented in a class that models the managerID and the 2 addtional fields

Adam Fox
A: 

Yes, from what you described, a ModelManager class, makes sense. The Model would then have a List of ModelManagers and the ModelManager class would have the Manager, Percentage and Owner.

Timothy Carter