Closed besi closed 10 years ago
The Active Admin Docs cover this issue:
Associated Sorting
You’re normally able to sort columns alphabetically, but by default you can’t sort by associated objects. Though with a few simple changes, you can.
Assuming you’re on the Books index page, and Book has_one Publisher:
controller do def scoped_collection resource_class.includes(:publisher) # prevents N+1 queries to your database end end
Then it’s simple to sort by any Publisher attribute from within the index table:
index do column :publisher, sortable: 'publishers.name' end
I have a model called
Programme
which has a translated attribute calledsummary
.When I enable sorting on that column I get an exception:
I tried to sort by
translations_summary
which leads to a similar issue.Curiously I can access the
summary
property of a given programme, but active_admin is not able to sort by this property. Is there a way toinclude(:translations)
like in the following scope-definition example?