Thursday, 12 September 2013

Choose relation one to many or many to one for design

Choose relation one to many or many to one for design

I need help to define the relationship between the models.
I have 2 models :
User
Product
The user own many products and the product is owned by only one user.
My use case : The logged user can access to some information in his
personnal account : - Display all his products - Add a new product
Later i'd like to add use case like : any user can see any product in some
screen (and know product's owner).
So, i can define the models like that :
A) ONE TO MANY
class User{
private Set<Product> products;
..
}
class Product{
...
}
B) MANY TO ONE
class User{
..
}
class Product{
private User owner;
}
Which is the best ? one to many or many to one ?
Because my use case display the product of logged user Im thinking its
better to choose one to many

No comments:

Post a Comment