Easyadminbundle: [3.0] AssociationField in the index-page looks sortable, but clickin it renders the index empty

Created on 24 Jun 2020  路  9Comments  路  Source: EasyCorp/EasyAdminBundle

Describe the bug
Explain what you wanted to do and the wrong result you got.

To Reproduce
Create a list with an AssociationField. It renders sortable/clickable. Clicking on it displays an empty index

(OPTIONAL) Additional context
If they are useful, include logs, code samples, screenshots, etc.
image

After clicking the Assigned To
image

bug confirmed

Most helpful comment

We would probably need a way to define the "sort fields" (Doctrine / DB level) on the target entity, and then use those to order the results.

The quick fix would be to just mark them as not sortable until there is a proper solution available. You can already do that manually for now with ->setSortable(false) on the field.

All 9 comments

I also have the problem.

We would probably need a way to define the "sort fields" (Doctrine / DB level) on the target entity, and then use those to order the results.

The quick fix would be to just mark them as not sortable until there is a proper solution available. You can already do that manually for now with ->setSortable(false) on the field.

@lukasluecke It is an excellent idea :)

I manually altered the search url with dot notation and it works.
sort%5BparentCompany%5D=DESC
to
sort%5BparentCompany.name%5D=DESC

So if its easier to somehow just alter how it generates the url

I did some digging through the code and managed to get it to work by adding a sort property for the association field. It checks if that property is valid for that entity or throws an exception.

If a sort property exists then the twig template will append the sortProperty to the field property name for the url eg sort=contact.name which seems to work fine with my testing.

Until the issue is fixed the best workaround I found is to add the related entity name and their property as properyName and set is as sortable for example:
yield TextField::new('unit.name', 'unit')->setSortable(true)->onlyOnIndex();

Apparently fixed by 91ef0ebb192aa9300988d3c8bf0eb80cc14ed45c.

Indeed, fixed

Yes but it broke other user cases. Check the issue https://github.com/EasyCorp/EasyAdminBundle/issues/3879

I think @JSmythSSG general idea of specifying sortProperty was a nice one :)

Was this page helpful?
0 / 5 - 0 ratings