Php 查询派生类型';在条令中使用继承时的属性
使用Doctrine的Php 查询派生类型';在条令中使用继承时的属性,php,orm,doctrine-orm,query-builder,Php,Orm,Doctrine Orm,Query Builder,使用Doctrine的QueryBuilder,在使用单表继承时,如何在派生类型的属性之一上指定where条件 假设我有一个类型AbstractBillingEntity,它有一个派生类型ComplexBillerComplexBiller本身有一个受保护的条令控制属性,名为organizationcode 如何使用QueryBuilder搜索类型为ComplexBiller且具有ComplexBiller.organizationcode>5的所有计费实体? $queryBui
QueryBuilder
,在使用单表继承时,如何在派生类型的属性之一上指定where条件
假设我有一个类型AbstractBillingEntity
,它有一个派生类型ComplexBiller
ComplexBiller
本身有一个受保护的条令控制属性,名为organizationcode
如何使用QueryBuilder
搜索类型为ComplexBiller
且具有ComplexBiller.organizationcode>5
的所有计费实体?
$queryBuilder->andWhere("billingEntity INSTANCE OF ComplexBiller")
$queryBuilder->andWhere(??)
使用条令2.4、PHP5.6,这是条令团队目前无法解决的一个老问题() 显然,Doctrine DQL语言的内部结构使得尝试和实现一种类型的强制转换成为了一种不遗余力的努力。虽然将来可能会考虑,但训练是对子类执行一个具有明确要求的子查询:
$subExpr = $this->em->createQueryBuilder()
->select("anEntity")
->from("ChildClass", "anEntity")
->where("orgEntity.derivedTypeAttr = :someParam");
$mainExpr = $this->em->createQueryBuilder()
->where($queryBuilder->expr()->in("billingEntity.id", $subExpr->getDQL()))
->setParameter("someParam", $myVal);
或者,在本机SQL中(取自非常有用的源代码)
SELECT
a
FROM
Entities\Auction a
INNER JOIN
a.item i
INNER JOIN
i.bookTypes b
WHERE
i.id IN (
SELECT
b.id
FROM
Entities\Book b
WHERE
b.type = 'Fantasy'
)