diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-22 13:58:22 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-22 13:58:22 +0000 |
commit | e9426d22646eed19627784ca07adc902f6c5fe9e (patch) | |
tree | a6ef6d10f0f92596d54749750ce4333f9de24057 /activerecord/lib | |
parent | dfd43d577eaaf4b9c157f6379045d1e2fb68d1ee (diff) | |
download | rails-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
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 |
2 files changed, 2 insertions, 2 deletions
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 |