[英]How to add condition in AssociationField in Symfony EasyAdmin
I'm building book management system.我正在构建图书管理系统。 where each books have many chapters.每本书都有很多章节。
When I filter the list chapter by book I want to when I create new chapter the association field book hidden or at least filtered by the current filter (book).当我按书过滤列表章节时,我想在创建新章节时隐藏或至少被当前过滤器(书)过滤的关联字段书。
AssociationField has a method called setQueryBuilder
which help you modify the query. AssociationField有一个名为setQueryBuilder
的方法,可以帮助您修改查询。
In your case, your association field should look like:在您的情况下,您的关联字段应如下所示:
AssociationField::new('chapters')
->setQueryBuilder(function ($queryBuilder) {
return $queryBuilder->andWhere(''); // your query
});
You could also use a repository and call its method but returning a query builder (and not the result) inside setQueryBuilder .您还可以使用存储库并调用其方法,但在setQueryBuilder 中返回查询构建器(而不是结果)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.