diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 1 |
2 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 114095b7ef..9cfd9b6d23 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -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? diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 18f6152cc0..7046420ebd 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -539,5 +539,4 @@ class RelationTest < ActiveRecord::TestCase assert ! hen.new_record? assert_equal 'hen', hen.name end - end |