Skip to content

Commit e8579c8

Browse files
committed
Add sort_joins to column, defaults to includes value
So it's possible to set sort by SQL without joining the includes, or join with some associations, and preload others.
1 parent 842be9a commit e8579c8

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

CHANGELOG.rdoc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
- Integrate LogicalQueryParser, supporting full logical search, or simplified searches with 'all keywords' and 'any keyword' operators
2-
- Display unauthorized column in form as show action, so show_ui or show override is used if exists
3-
- Display unauthorized subform with show_ui as show action, to display readonly subform tables
4-
- Add subform_includes to column, and preload_for_form method to preload associations on edit action, speed up on big forms with long subforms or many nested subforms
5-
- Speedup on refreshing columns and saving big forms
6-
- Support add_new with chosen bridge
7-
- Added translations for millisec and microsec prompts in jquery UI datetime picker
8-
- Speed up validating big forms (e.g. nested subforms with many records on each subform)
9-
- Support hiding field descriptions by default and show them with hover or click
10-
- Fix for usage with frozen literal strings enabled, add magic comments to enable frozen string literals in ActiveScaffold
11-
- Update code for tabs to work with bootstrap 5
12-
- Add ActiveScaffold.setup_callbacks array, so functions can be added to be called when ActiveScaffold.setup is called (form open, page load)
13-
- Add add_new_link to config.nested, adding a link to create form on an association, refreshing this record instead of adding new row in the list
1+
- Integrate LogicalQueryParser, supporting full logical search, or simplified searches with 'all keywords' and 'any keyword' operators.
2+
- Display unauthorized column in form as show action, so show_ui or show override is used if exists.
3+
- Display unauthorized subform with show_ui as show action, to display readonly subform tables.
4+
- Add subform_includes to column, and preload_for_form method to preload associations on edit action, speed up on big forms with long subforms or many nested subforms.
5+
- Speedup on refreshing columns and saving big forms.
6+
- Support add_new with chosen bridge.
7+
- Added translations for millisec and microsec prompts in jquery UI datetime picker.
8+
- Speed up validating big forms (e.g. nested subforms with many records on each subform).
9+
- Support hiding field descriptions by default and show them with hover or click.
10+
- Fix for usage with frozen literal strings enabled, add magic comments to enable frozen string literals in ActiveScaffold.
11+
- Update code for tabs to work with bootstrap 5.
12+
- Add ActiveScaffold.setup_callbacks array, so functions can be added to be called when ActiveScaffold.setup is called (form open, page load).
13+
- Add add_new_link to config.nested, adding a link to create form on an association, refreshing this record instead of adding new row in the list.
1414
- Support hashes in update_columns, keys are association names or :__root__ to refresh fields on subforms or at top of the form, values are list of columns or nested hashes.
1515
- Add custom_modules, in active_scaffold_config and global, to add modules which will be included after ActiveScaffold action modules, to customize the controllers.
16-
- Add active_scaffold_subform_record_actions helper to render the destroy action on the rows of a subform, so it can be used to add more actions
17-
- Improve ActiveStorage bridge to keep existing files in has_many_attachments
18-
- Helpers used by file upload bridges have been renamed and moved the JS code to active_scaffold.js
19-
- Support action link groups to open with click, like actions showing dynamic action link group
20-
- Open dynamic action link group nested in the menu tree, under the action opening it
16+
- Add active_scaffold_subform_record_actions helper to render the destroy action on the rows of a subform, so it can be used to add more actions.
17+
- Improve ActiveStorage bridge to keep existing files in has_many_attachments.
18+
- Helpers used by file upload bridges have been renamed and moved the JS code to active_scaffold.js.
19+
- Support action link groups to open with click, like actions showing dynamic action link group.
20+
- Open dynamic action link group nested in the menu tree, under the action opening it.
21+
- Add sort_joins to column, defaults to includes value, so it's possible to set sort by SQL without joining the includes, or join with some associations, and preload others.
2122

2223
= 4.1.4
2324
- Fix dirty attributes on refresh_field action, record is built on unsaved instance copying attributes, but it reports only changed attributes from the form now

lib/active_scaffold/actions/list.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ def action_links_menu_respond_to_js
8888
def set_includes_for_columns(action = :list, sorting = active_scaffold_config.list.user.sorting)
8989
@cache_associations = true
9090
columns = columns_for_action(action)
91-
joins_cols, preload_cols = columns.select { |c| c.includes.present? }.partition do |col|
92-
includes_need_join?(col, sorting) && !grouped_search?
93-
end
94-
active_scaffold_references.concat joins_cols.map(&:includes).flatten.uniq
95-
active_scaffold_preload.concat preload_cols.map(&:includes).flatten.uniq
91+
joins_cols = columns.select { |col| col.sort_joins.present? && includes_need_join?(col, sorting) && !grouped_search? }
92+
active_scaffold_references.concat joins_cols.map(&:sort_joins).flatten.uniq
93+
active_scaffold_preload.concat columns.filter_map { |c| c.includes.presence }.flatten.uniq
9694
set_includes_for_sorting(columns, sorting) if sorting.sorts_by_sql?
9795
end
9896

lib/active_scaffold/data_structures/column.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ def sort_by(options)
191191
self.sort = options
192192
end
193193

194+
# a collection of associations to do left join when the list is sorted by this column
195+
def sort_joins
196+
@sort_joins || includes
197+
end
198+
199+
def sort_joins=(value)
200+
@sort_joins =
201+
case value
202+
when Array then value
203+
else [value] # automatically convert to an array
204+
end
205+
end
206+
194207
def associated_number?
195208
@associated_number
196209
end

0 commit comments

Comments
 (0)