我有一个超类和LibraryCommon
4 个子类型:Library
、PurchasedLibrary
和.PurchasableLibrary
PersonalLibrary
Library
是一个LibraryCommon
没有附加字段的简单扩展,PurchasedLibrary
有一个用户实体。在一个实例中,我想要所有Libraries
属于PurchasedLibraries
某个用户的所有内容。
所以我在中创建了一个方法LibraryCommonRepository
:
public function findLibraries($user)
{
return $this->createQueryBuilder('l')
->where('l INSTANCE OF Library')
->orWhere('l INSTANCE OF PurchasedLibrary AND l.user = :user')
->setParameter(':user', $user)
->getQuery()
->getResult()
;
}
但是,此错误为[Semantical Error] line 0, col 182 near 'user = :user': Error: Class LibraryCommon has no field or association named user
.
我错过了什么,还是我真的需要加入两个单独的查询才能得到我想要的结果?
此外,如果我不提供用户并这样做:
public function findLibraries()
{
return $this->createQueryBuilder('l')
->where('l INSTANCE OF Library OR l INSTANCE OF PurchasedLibrary')
->getQuery()
->getResult()
;
}
生成的查询如下所示:
SELECT
...
FROM
library l0_
WHERE
(
l0_.type IN ('library')
OR l0_.type IN ('purchased')
)
AND l0_.type IN (
'library', 'personal', 'purchased',
'purchasable'
)
有没有办法让查询只是做WHERE l0_.type IN ('library', 'purchased')