Permalink
Browse files

Removed the default order by id on has_and_belongs_to_many queries as…

… it could kill performance on large sets (you can still specify by hand with :order)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1162 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 54cc595 commit 71bdf13b60bb8ac6a06f05eea94399bf9de27a92 @dhh dhh committed Apr 13, 2005
View
@@ -1,5 +1,7 @@
*SVN*
+* Removed the default order by id on has_and_belongs_to_many queries as it could kill performance on large sets (you can still specify by hand with :order)
+
* Fixed that Base.silence should restore the old logger level when done, not just set it to DEBUG #1084 [yon@milliped.com]
* Fixed boolean saving on Oracle #1093 [mparrish@pearware.org]
@@ -7,7 +7,7 @@ def initialize(owner, association_name, association_class_name, association_clas
@association_foreign_key = options[:association_foreign_key] || Inflector.underscore(Inflector.demodulize(association_class_name)) + "_id"
@association_table_name = options[:table_name] || @association_class.table_name
@join_table = options[:join_table]
- @order = options[:order] || "t.#{@association_class.primary_key}"
+ @order = options[:order]
construct_sql
end
@@ -146,12 +146,18 @@ def delete_records(records)
def construct_sql
interpolate_sql_options!(@options, :finder_sql, :delete_sql)
- @finder_sql = @options[:finder_sql] ||
- "SELECT t.*, j.* FROM #{@join_table} j, #{@association_table_name} t " +
- "WHERE t.#{@association_class.primary_key} = j.#{@association_foreign_key} AND " +
- "j.#{@association_class_primary_key_name} = #{@owner.quoted_id} " +
- (@options[:conditions] ? " AND " + interpolate_sql(@options[:conditions]) : "") + " " +
- "ORDER BY #{@order}"
+
+ if @options[:finder_sql]
+ @finder_sql = @options[:finder_sql]
+ else
+ @finder_sql =
+ "SELECT t.*, j.* FROM #{@join_table} j, #{@association_table_name} t " +
+ "WHERE t.#{@association_class.primary_key} = j.#{@association_foreign_key} AND " +
+ "j.#{@association_class_primary_key_name} = #{@owner.quoted_id} "
+
+ @finder_sql << " AND #{interpolate_sql(@options[:conditions])}" if @options[:conditions]
+ @finder_sql << "ORDER BY #{@order}" if @order
+ end
end
end
end

0 comments on commit 71bdf13

Please sign in to comment.