<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1486,10 +1486,15 @@ module ActiveRecord
             join_dependency.joins_for_table_name(table)
           }.flatten.compact.uniq
 
+          order = options[:order]
+          if scoped_order = (scope &amp;&amp; scope[:order])
+            order = order ? &quot;#{order}, #{scoped_order}&quot; : scoped_order
+          end
+
           is_distinct = !options[:joins].blank? || include_eager_conditions?(options, tables_from_conditions) || include_eager_order?(options, tables_from_order)
           sql = &quot;SELECT &quot;
           if is_distinct
-            sql &lt;&lt; connection.distinct(&quot;#{connection.quote_table_name table_name}.#{primary_key}&quot;, options[:order])
+            sql &lt;&lt; connection.distinct(&quot;#{connection.quote_table_name table_name}.#{primary_key}&quot;, order)
           else
             sql &lt;&lt; primary_key
           end
@@ -1503,8 +1508,8 @@ module ActiveRecord
           add_conditions!(sql, options[:conditions], scope)
           add_group!(sql, options[:group], scope)
 
-          if options[:order] &amp;&amp; is_distinct
-            connection.add_order_by_for_association_limiting!(sql, options)
+          if order &amp;&amp; is_distinct
+            connection.add_order_by_for_association_limiting!(sql, :order =&gt; order)
           else
             add_order!(sql, options[:order], scope)
           end</diff>
      <filename>activerecord/lib/active_record/associations.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>34510456585216004e483b79beeea3ddc3eb4de6</id>
    </parent>
  </parents>
  <author>
    <name>Tarmo T&#228;nav</name>
    <email>tarmo@itech.ee</email>
  </author>
  <url>http://github.com/rails/rails/commit/8c91b767c0f36e9d767eb230ec42b111e57d90da</url>
  <id>8c91b767c0f36e9d767eb230ec42b111e57d90da</id>
  <committed-date>2008-07-14T22:44:58-07:00</committed-date>
  <authored-date>2008-07-14T19:17:06-07:00</authored-date>
  <message>Fixed postgresql limited eager loading for the case where scoped :order was present</message>
  <tree>a7fdfc72ea67d2992e5776703efaf87a16b49a07</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
