PHP:不确定如何建模数据库关系
在我的数据库中,我有一个表“收藏夹”和一个表“活动”。我正在使用 Zend Framework,并且有一个对两个表进行建模的类。现在,当有人喜欢一篇文章时,我必须在活动表中添加一行。
最明显的方法是在相应的表类中创建方法 addActivity 和 addFavorite,每当一篇文章被收藏时,我都会调用 addActivity 方法。虽然这很简单,但对我来说似乎并不自然。
您对更好的方法有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去也遇到过同样的问题。我使用您的本体论解决了这个问题,并在活动表中使用静态方法,调用类似于:
是的,它看起来不自然。
恐怕您在这里谈论的是方面方向...
另一种方法(但由于其他原因没有选择它)是向数据库添加一个触发器,该触发器将填充
活动,每次添加收藏夹时。我不想去那里,因为它在文献中被夸大了,很快就会触发
失控。这取决于您希望在数据库级别拥有多少应用程序逻辑......
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...