In my database I have a table ‘favorites’ and a table ‘activity’. I am using the Zend Framework and I have a class modeling both tables. Now, when someone favorites an article then I have to add a row in the activity table.
The most obvious way to do this would be to create the methods addActivity and addFavorite in the respective table classes, and whenever an article is favorited I would call then addActivity method. Although this is very straightforward, it doesn’t seem natural to me.
Do you have any suggestions on a better way to do this?
I had faced the same problem in the past. I had it solved, using your ontology, with a static method in the activity table the call was something like:
and yes it looks un-natural.
You are talking about Aspect Orientation here, I’m afraid…
Another way to do it (but did not choose it for other reasons), would be by adding a trigger to the database, which would populate
activity, each time a favourite was added. I did not want to go there because it is overstated in the literature that triggers soon
get out of control. This depends on how much application logic you want to have on database level…