1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Give preference to the second relation's order when merging

This commit is contained in:
Pratik Naik 2010-01-03 18:47:34 +05:30
parent d531cbc809
commit 3eca0ab838
2 changed files with 10 additions and 4 deletions

View file

@ -38,13 +38,16 @@ module ActiveRecord
merged_relation = merged_relation.
joins(arel.joins(arel)).
group(arel.groupings).
order(arel.send(:order_clauses).join(', ')).
limit(arel.taken).
offset(arel.skipped).
select(arel.send(:select_clauses)).
from(arel.sources)
end
relation_order = r.send(:order_clause)
merged_order = relation_order.present? ? relation_order : order_clause
merged_relation = merged_relation.order(merged_order)
merged_wheres = @relation.wheres
r.wheres.each do |w|
@ -83,7 +86,7 @@ module ActiveRecord
:select => @relation.send(:select_clauses).join(', '),
:joins => @relation.joins(relation),
:group => @relation.send(:group_clauses).join(', '),
:order => @relation.send(:order_clauses).join(', '),
:order => order_clause,
:conditions => where_clause,
:limit => @relation.taken,
:offset => @relation.skipped,
@ -156,7 +159,7 @@ module ActiveRecord
end
def reset
@first = @last = @create_scope = @to_sql = nil
@first = @last = @create_scope = @to_sql = @order_clause = nil
@records = []
self
end
@ -219,6 +222,10 @@ module ActiveRecord
@relation.send(:where_clauses).join(join_string)
end
def order_clause
@order_clause ||= @relation.send(:order_clauses).join(', ')
end
def references_eager_loaded_tables?
joined_tables = (tables_in_string(@relation.joins(relation)) + [table.name, table.table_alias]).compact.uniq
(tables_in_string(to_sql) - joined_tables).any?

View file

@ -539,5 +539,4 @@ class RelationTest < ActiveRecord::TestCase
assert ! hen.new_record?
assert_equal 'hen', hen.name
end
end