-1

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).

Noor Wachid
  • 39
  • 1
  • 4

1 Answers1

2

AssociationField has a method called setQueryBuilder which help you modify the query.

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.

Select0r
  • 12,234
  • 11
  • 45
  • 68
Dylan KAS
  • 4,840
  • 2
  • 15
  • 33