Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

Symfony, easyadmin filter via relation

I use Easyadmin bundle for the administrative part of the web-application and I use configuration like this:

easy_admin:
  entities:
    Payment:
      class: AppEntityPayment
      controller: AppControllerCompanyController
      label: 'payments'
      list:
        item_permission: ['ROLE_ADMIN','ROLE_COMPANY_OWNER','ROLE_COMPANY_ACCOUNTANT']
        actions: ['show', '-delete', '-edit', '-new']
        collapse_actions: true
        title: 'Payments'
        filters:
          - { property: 'id', label: 'id' }
          - { property: 'type', label: 'type' }
          - { property: 'user', label: 'user' }
          ...

The problem is about I can't set filter via entity relation, like { property: 'user.company', label: 'company' }, it throws exception that property does not exist or misconfigurated. Does anybody have any idea how to solve this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can use Static Filters (dql_filter Option) The dql_filter option lets you define the conditions passed to the WHERE clause of the Doctrine query used to get the entities displayed in the list and search views.

for exemple

easy_admin:
    entities:
        VipCustomers:
            class: AppEntityUser
            list:
                dql_filter: 'entity.budget > 100000'
        RegularCustomers:
            class: AppEntityUser
            list:
                dql_filter: 'entity.budget <= 100000'

and in your case i think you can do something like this.

easy_admin:
  entities:
    Payment:
      class: AppEntityPayment
      controller: AppControllerCompanyController
      label: 'payments'
      list:
        item_permission: ['ROLE_ADMIN','ROLE_COMPANY_OWNER','ROLE_COMPANY_ACCOUNTANT']
        actions: ['show', '-delete', '-edit', '-new']
        collapse_actions: true
        title: 'Payments'
        dql_filter: "user.company"
           

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...