Skip to content
This repository
Browse code

Optimized the SQL used to generate has_and_belongs_to_many queries by…

… listing the join table first #693 [yerejm]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@741 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit e9426d22646eed19627784ca07adc902f6c5fe9e 1 parent dfd43d5
David Heinemeier Hansson authored
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Optimized the SQL used to generate has_and_belongs_to_many queries by listing the join table first #693 [yerejm]
  4
+
3 5
 * Fixed that when using validation macros with a custom message, if you happened to use single quotes in the message string you would get a parsing error #657 [tonka]
4 6
 
5 7
 * Fixed that Active Record would throw Broken Pipe errors with FCGI when the MySQL connection timed out instead of reconnecting #428 [Nicholas Seckar]
2  activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -147,7 +147,7 @@ def delete_records(records)
147 147
         def construct_sql
148 148
           interpolate_sql_options!(@options, :finder_sql, :delete_sql)
149 149
           @finder_sql = @options[:finder_sql] ||
150  
-                "SELECT t.*, j.* FROM #{@association_table_name} t, #{@join_table} j " +
  150
+                "SELECT t.*, j.* FROM #{@join_table} j, #{@association_table_name} t " +
151 151
                 "WHERE t.#{@association_class.primary_key} = j.#{@association_foreign_key} AND " +
152 152
                 "j.#{@association_class_primary_key_name} = #{@owner.quoted_id} " +
153 153
                 (@options[:conditions] ? " AND " + interpolate_sql(@options[:conditions]) : "") + " " +
2  activerecord/lib/active_record/base.rb
@@ -144,7 +144,7 @@ class StaleObjectError < ActiveRecordError #:nodoc:
144 144
   #   class Client < Company; end
145 145
   #   class PriorityClient < Client; end
146 146
   #
147  
-  # When you do Firm.create("name" => "37signals"), this record with be saved in the companies table with type = "Firm". You can then
  147
+  # When you do Firm.create("name" => "37signals"), this record will be saved in the companies table with type = "Firm". You can then
148 148
   # fetch this row again using Company.find_first "name = '37signals'" and it will return a Firm object.
149 149
   #
150 150
   # If you don't have a type column defined in your table, single-table inheritance won't be triggered. In that case, it'll work just

0 notes on commit e9426d2

Please sign in to comment.
Something went wrong with that request. Please try again.