4 回答
TA贡献1834条经验 获得超8个赞
您所需要的只是在 where 子句中添加entity.:)
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response->where('entity.isDeleted = 1');
return $response;
}
TA贡献1794条经验 获得超8个赞
这对我的 EasyAdmin 4.x 有用
use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
class CampaignCrudController extends AbstractCrudController
{
public function __construct(EntityRepository $entityRepository)
{
$this->entityRepository = $entityRepository;
}
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): ORMQueryBuilder
{
$response = $this->entityRepository->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response->andWhere('entity.user = :user')->setParameter('user', $this->getUser());
return $response;
}
TA贡献1812条经验 获得超5个赞
EasyAdmin4解决方案
注意:关键字(别名)entity很重要
use Doctrine\ORM\QueryBuilder;
class ArticleCrudController extends AbstractCrudController
{
...
public function configureFields(string $pageName): iterable
{
return [
...
AssociationField::new('author')->setQueryBuilder(
fn (QueryBuilder $queryBuilder) => $queryBuilder
->leftJoin('entity.article', 'a')
->andWhere('entity.isActive = 1')
->andWhere('a.author is NULL')
),
...
]
}
...
}
TA贡献1803条经验 获得超6个赞
对于每个使用接受的答案并通过搜索找到以下 QueryException 的人:
QueryException
Too many parameters: the query defines 1 parameters and you bound 3
EntityCrudController 内的 EasyAdmin v3.x:
使用->andWhere()函数
使用实体。作为前缀(实际上,使用“实体”,不要替换为您的实体名称)
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
$response = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response->andWhere('entity.isDeleted = 1');
return $response;
}
- 4 回答
- 0 关注
- 136 浏览
添加回答
举报