Created by: sejinkim1904
What does this PR do?
- Updates
Orderto be able to sort bybelongs_tofield- Updates
initializeto take inassociation_attribute - Adds
order_by_association_attribute - Adds
order_by_attribute - Updates
order_by_associationto useorder_by_attributeforbelongs_toassociations - Adds
association_has_attribute?
- Updates
- Adds
belongs_to_sorting_fieldtoApplicationControllerto be overridden by users to select which field to sort by - Adds
belongs_to_sorting_attributetoOrdersControllerfor testing - Updates/adds tests to specs
- Adds
Customizing belongs_to Sorting Fieldsection in/docs/customizing_controller_actions.md
How should this be manually tested?
- Start local server
- Visit
/admin/orders - Click on 'Customer'
Any background context you want to provide?
My team currently uses administrate in our application and we noticed when trying to sort by a belongs_to association, by default it sorts by the association's id. We found a workaround by sub-classing Administrate::Order in our controller to be able to sort by an association's field. Our implementation was very specific to our data model but I thought this feature could be useful for future or current devs so I decided to create a more dynamic version.
Screenshots (if appropriate)
Before:
class OrdersController < Admin::ApplicationController
end
After:
class OrdersController < Admin::ApplicationController
def belongs_to_sorting_attribute
:name
end
end
Questions:
- Do Migrations Need to be ran? NO
- Do Environment Variables need to be set? NO
- Any other deploy steps? NO

