Data modeling for user-favored tasks

1

I have an application where the user can create a task. The task in turn can be public or private. If it's public, other users can view it and favor it. That is, many users can favor the same task.

I thought about creating a third table, called Favorites. In this table I will have two fields, User_id (which is the face that favored the task) and Task_id (which is the favorite task.

When I need to show this I filter via code. Are you sure this or do you suggest something better?

    
asked by anonymous 04.08.2014 / 02:40

1 answer

3

Every relationship that is understood as "many-to-many" needs an intermediate table, such as the one you have made explicit.

In this case, since a person can favor several tasks and a task can be favored by several people, an association table between the two entities is necessary for this behavior to be registered.

I also advise to put primary key as the combination of 2 fields (thus avoiding a favorite person the same task more than once, assuming this is not possible) and a column with the date that the event occurred, for registration purposes

    
04.08.2014 / 02:49