0

I have a site written in cakephp with a mysql database. Into my site I want to track the activities of every users, for example (like this site) if a user insert a product I want to put this activity into my database. I have 2 ways: 1) One table called Activities with: - id - user_id - title - text - type (the type of activity: comment, post edit)

2) more table differenced by activities - table activities_comment - table activities_post - table activities_badges

The problem is when I go to the page activities of a user I can have different type of activities and I don't know which of this solution is better because a comment has a title and a comment, a post has only a text, a badge has an external id to its table (for example) ecc... Help me please

1 Answers1

2

I'm not familiar with CakePHP, but from purely database perspective your data model should probably look similar to this:

enter image description here

The enter image description here symbol denotes category (aka. inheritance, subclass, subtype, generalization hierarchy etc.). Take a look at "Subtype Relationships" in ERwin Methods Guide for more info.

There are generally 3 strategies for implementing the category:

  1. All types in single table. This requires a lot of NULLs and requires CHECKs to make sure separate subtypes are not inappropriately "intermingled".
  2. All concrete types in separate tables (excluding the base, which is ACTIVITY in your case), which means common fields and relationships must be repeated in all child tables.
  3. All types in separate tables (including the base). This implementation requires a little more JOINing, but is flexible and clean. It should be your default, unless there are strong reasons against it.
Branko Dimitrijevic
  • 50,809
  • 10
  • 93
  • 167