aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-22 13:58:22 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-22 13:58:22 +0000
commite9426d22646eed19627784ca07adc902f6c5fe9e (patch)
treea6ef6d10f0f92596d54749750ce4333f9de24057
parentdfd43d577eaaf4b9c157f6379045d1e2fb68d1ee (diff)
downloadrails-e9426d22646eed19627784ca07adc902f6c5fe9e.tar.gz
rails-e9426d22646eed19627784ca07adc902f6c5fe9e.tar.bz2
rails-e9426d22646eed19627784ca07adc902f6c5fe9e.zip
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
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
3 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 6e031edb60..6da6b5c9a2 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Optimized the SQL used to generate has_and_belongs_to_many queries by listing the join table first #693 [yerejm]
+
* 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]
* Fixed that Active Record would throw Broken Pipe errors with FCGI when the MySQL connection timed out instead of reconnecting #428 [Nicholas Seckar]
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
index 77d2fb9cde..5ccac8e62b 100644
--- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -147,7 +147,7 @@ module ActiveRecord
def construct_sql
interpolate_sql_options!(@options, :finder_sql, :delete_sql)
@finder_sql = @options[:finder_sql] ||
- "SELECT t.*, j.* FROM #{@association_table_name} t, #{@join_table} j " +
+ "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]) : "") + " " +
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index e00f0d31bc..0c086183dc 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -144,7 +144,7 @@ module ActiveRecord #:nodoc:
# class Client < Company; end
# class PriorityClient < Client; end
#
- # When you do Firm.create("name" => "37signals"), this record with be saved in the companies table with type = "Firm". You can then
+ # When you do Firm.create("name" => "37signals"), this record will be saved in the companies table with type = "Firm". You can then
# fetch this row again using Company.find_first "name = '37signals'" and it will return a Firm object.
#
# 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