4 回答

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
您所需要的只是在 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貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
這對(duì)我的 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貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
EasyAdmin4解決方案
注意:關(guān)鍵字(別名)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貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊
對(duì)于每個(gè)使用接受的答案并通過(guò)搜索找到以下 QueryException 的人:
QueryException
Too many parameters: the query defines 1 parameters and you bound 3
EntityCrudController 內(nèi)的 EasyAdmin v3.x:
使用->andWhere()函數(shù)
使用實(shí)體。作為前綴(實(shí)際上,使用“實(shí)體”,不要替換為您的實(shí)體名稱)
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 關(guān)注
- 194 瀏覽
添加回答
舉報(bào)