【发布时间】:2013-11-13 19:56:09
【问题描述】:
我正在构建一个社交网站,并且正在展示 Feed 的工作方式。我想在这里使用答案:How to implement the activity stream in a social network 并实现提到的数据库设计:
id
user_id (int)
activity_type (tinyint)
source_id (int)
parent_id (int)
parent_type (tinyint)
time (datetime but a smaller type like int would be better)
问题是我不知道如何根据activity_type 映射source_id。如果用户注册,我希望 source_id 成为注册用户。如果有人创建了一个组,source_id 将是该组。我知道我可以只使用没有密钥的简单 ID 我只是想知道 Symfony 是否有某种内置方法来做到这一点。
如果我获取提要并且 activity_type 是 user_register,我希望能够在不运行其他查询的情况下获取源(用户):
$feedEntity->getSource()->getUsername(); //getSource() being the User entity
如果source_type是“user_post”:
$feedEntity->getSource()->getMessage(); //getSource() being the UserPost entity
我基本上只是想找到存储这些数据的最佳方式并使其最快。
【问题讨论】:
标签: symfony dynamic types field