我有几个实体,
Food
GroupsOption
哪个有
one-to-many
这种关系意味着每种食物都可能没有任何选择或有多组选择。在我下面的查询中,我想过滤没有任何分组选项的食物。这是我的密码:
$result = $qb->select(
"partial Food.{
foodId,
foodName
}",
->from($this->entityClass, "Food")
->leftJoin("Food.groupsOption", "OptionGroup")
->addSelect("OptionGroup")
->getQuery()
->getResult();
#items: array:2 [
0 => Food {#
.
.
.
#groupsOption: PersistentCollection {#1157
-snapshot: array:1 [ â¦1]
-owner: Food {#1065}
-association: array:15 [ â¦15]
-em: EntityManager {#272 â¦11}
-backRefFieldName: "food"
-typeClass: ClassMetadata {#1112 â¦}
-isDirty: false
#collection: ArrayCollection {#1158
-elements: array:1 [
.
.
.
]
]
1 => Food {#
.
.
.
#groupsOption: PersistentCollection {#1383
-snapshot: []
-owner: Food {#1371}
-association: array:15 [ â¦15]
-em: EntityManager {#272 â¦11}
-backRefFieldName: "food"
-typeClass: ClassMetadata {#1112 â¦}
-isDirty: false
#collection: ArrayCollection {#1382
-elements: []
}
#initialized: true
}
]
它给了我所有的结果,但我只是想把它改成我以前说过的。
有什么建议吗?