Skip to content

Commit 1610ad8

Browse files
aldhsuJames Crisp
authored andcommitted
Add comment for order by query and fix typo
1 parent 346d001 commit 1610ad8

2 files changed

Lines changed: 1 addition & 2 deletions

File tree

lib/jsonapi/resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ def apply_sort(records, order_options, _context = {})
537537
associations = _lookup_association_chain([records.model.to_s, *model_names])
538538
joins_query = _build_joins([records.model, *associations])
539539

540+
# _sorting is appended to avoid name clashes with manual joins eg. overriden filters
540541
order_by_query = "#{associations.last.name}_sorting.#{column_name} #{direction}"
541542
records = records.joins(joins_query).order(order_by_query)
542543
else

test/controllers/controller_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ def test_desc_sorting_by_relationship_field
327327
assert_equal post.id.to_s, json_response['data'][-2]['id'], 'alphabetically first user is second last'
328328
end
329329

330-
end
331-
332330
def test_invalid_sort_param
333331
get :index, params: {sort: 'asdfg'}
334332

0 commit comments

Comments
 (0)