Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Fix Reported issue involving reoder and last #419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/squeel/adapters/active_record/4.1/relation_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def build_from
def build_order(arel)
orders = order_visit(dehashified_order_values)
orders = orders.uniq.reject(&:blank?)
orders = reverse_sql_order(orders) if reverse_order_value && !reordering_value
if reverse_order_value && (!reordering_value || Array(order_values).any?(&:present?))
orders = reverse_sql_order(orders)
end

arel.order(*orders) unless orders.empty?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ module ActiveRecord
sql.should_not match /ORDER BY/
end

it 'reverses the order if used with last' do
expected = Person.all.sort_by { |p| p.id }.last
result = Person.reorder(:id).last
result.should eq(expected)
end
end

describe '#from' do
Expand Down