我有两个实体,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
}
]
它给了我所有结果,但我只是想将其更改为我之前说过的内容。
有什么建议吗?