【发布时间】:2018-03-02 18:36:18
【问题描述】:
我有类似的桌子
profilestatus
Profile.class
id name
1 taro
2 jiro
3 john
状态类
id profile school date
1 1 highschool 2017-04-01
2 1 juniorhighschool 2013-04-01
3 2 highschool 2017-04-01
状态改变时添加状态。
所以我通常每次需要状态时都会选择最新状态。
$ss = $this->em->createQuery(
"SELECT cm FROM UserBundle:Status s where c.profile = :p order by desc")
->setParameters(['p' => $profile])->getResult();
$ss[0] // Latest Status
所以现在我想把它放在函数中。
我想做的是从个人资料中获取最新状态。
我有一些想法
- 把这个函数放在 Profile Entity 中?
- 将此函数放入配置文件存储库?
- 将此功能投入使用???
在我看来它应该是 Profile Entity 的功能,所以我想把它放在 Entity 中,从 Entity 访问另一个是不好的方式。
可以从 Profile Repository 访问另一个实体吗?
或者我应该使用服务吗??
【问题讨论】:
-
完全可以接受配置文件存储库返回状态实体。
标签: symfony repository entity