过滤子实体属性的准则

时间:2019-06-28 15:14:21

标签: doctrine

如何使用Doctrine的条件对子实体的属性进行过滤?

例如,如果我有一个带有以下实体的userCollection

[
  {"birthday":"1982-02-17","mother":{"name":"JaneDoe"}},
  {"birthday":"1982-02-17","mother":{"name":"MaryDoe"}},
  {"birthday":"1982-02-17","mother":{"name":"SusanDoe"}}
 ]

如何返回生日为1982-02-17并且母亲的名字为JaneDoe的所有实体?

$criteria = Criteria::create()
    ->where(Criteria::expr()->eq("birthday", "1982-02-17"))
    ->where(Criteria::expr()->eq("mother->name", "JaneDoe"))
;
$birthdayUsers = $userCollection->matching($criteria);

我知道通常不会以这种方式使用“教义”,但是我在mother实体中有一个自然键(比一个名字好得多!),而不必先请求{{ 1}}实体优先。

0 个答案:

没有答案