我被困在这几个小时.
我有管理类列出所有类别,在一个表列中有相关产品(产品实体):表示例 相关代码:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('products') // Entity Product, @ORM\OneToMany
->add('ord')
;
}
Run Code Online (Sandbox Code Playgroud)
我需要做的是隐藏基于"(boolean)product.active"列出的非活动产品,但我无法弄明白.我知道"createQuery"方法,但它不起作用.当我生成SQL并直接运行查询时,它可以工作,但在这里看起来我只能使用ProxyQuery过滤类别,然后在单独的查询中查询所有产品(而这个单独的查询我不知道如何更改).
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$q = new ProxyQuery($query->join(sprintf('%s.products', $query->getRootAlias()), 'p')
->andWhere('p.active = :act')->setParameter('act', true));
return $q;
}
Run Code Online (Sandbox Code Playgroud)
感谢您的任何帮助