activescaffold/active_scaffold — Issue #107: When using nested scaffold action, sorting on the nested scaffold breaks when using sort_by method...
Author: jamescook000
Created: 2011-12-20 04:54:09+00:00
State: open

What steps will reproduce the problem?
1. Create scaffold hosts [id,hostname]
2. Create scaffold hosts_boards [host_id,boardmodel_id,boardver_id]
3. Create scaffold boardmodels [id,board_model]
4. Create scaffold boardvers [id,board_ver]
5. Add sorting on hosts_boards

config.columns[:boardmodel].sort_by :sql => "boardmodels.board_model"
config.columns[:boardvers].sort_by :sql => "boardvers.board_ver"
config.list.sorting = { :boardmodel => :asc }

6. Add nested link on boardmodels

[config.nested.add_link(:host_boards, :label => "Host Boards")]

7. Add nested link on boardvers

[config.nested.add_link(:host_boards, :label => "Host Boards")]

What is the expected output? What do you see instead?

When selecting the nested action link on the boardmodels and boardsvers I would expect the nested scaffold to appear and sorted by boardmodel sort_by method (ie 'board_models.boardmodel).

This will only work on the controller if the field being sorted by is not the controller you are showing the nested scaffold from ie:

Sorted by boardmodel will work on boardvers controller,
Sorted by boardver will work on boardmodels controller,
Sorted by boardmodel will NOT work on boardmodels controller,
Sorted by boardver will NOT work on boardvers controller,

If the sort_by method is NOT defined for either fields then either case will work. This is not really ideal as I dont want to sort by id and would like to use the field in the sort_by definition.

If the sorting is on the model you are using the sort_by method to show nested then mysql will error with:

ActiveRecord::StatementInvalid (Mysql2::Error: Unknown column 'board_models.boardmodel' in 'order clause'...

This used to work in rails below version 3.0.

What version (or revision) of the product are you using?

Active Scaffold 3.0.25

Regards
James