Search code examples
mysqldatabaseentity-relationshipdata-modeling

How to setup relation between three entites with classes


I have four classes

  1. User
  2. profiles
  3. Activity
  4. Workbook

  1. user can have many profiles based on per year. Every year diff profile
  2. User profile will have many to many with Activities

so there will be profile_activities table with profile_id and activity_id

Now User will do 1 workbook per activity per profile

so i am confused how to map in database


Solution

  • I've revised my suggestion in light of your comment.

    Perhaps could have an UserActivity class which has an Activity property and a Workbook property.

    Then you can have a User class with a property that is a list of Profile classes, and the Profile class will have a property that is a list of UserActivity classes.

    This satisfies your object model.

    So the UserActivity table will have a foreign key to a row in the Profile table (which will be its parent ID), and foreign keys to the Activity and Workbook tables.

    Your Profile table has a foreign key to a row in the User table which is its parentID.