aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-14 13:55:17 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-14 13:55:17 +0000
commit68d1056587d96cf3a413253cde126f2522d36c64 (patch)
treeac3ceafa1e944b89256de413ab122cb01f6684d5 /activerecord
parentc80f974fa3071104397d8dd5752ff60bca1881fe (diff)
downloadrails-68d1056587d96cf3a413253cde126f2522d36c64.tar.gz
rails-68d1056587d96cf3a413253cde126f2522d36c64.tar.bz2
rails-68d1056587d96cf3a413253cde126f2522d36c64.zip
Fixed that has_and_belongs_to_many would generate bad sql when naming conventions differed from using vanilla "id" everywhere [RedTerror]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@152 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb8
2 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 838d8d252a..78243608cd 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*CVS*
+* Fixed that has_and_belongs_to_many would generate bad sql when naming conventions differed from using vanilla "id" everywhere [RedTerror]
+
* Added a better exception for when a type column is used in a table without the intention of triggering single-table inheritance. Example:
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'bad_class!'.
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 d53650fbd8..0da243786e 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
@@ -3,16 +3,16 @@ module ActiveRecord
class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc:
def initialize(owner, association_name, association_class_name, association_class_primary_key_name, join_table, options)
super(owner, association_name, association_class_name, association_class_primary_key_name, options)
-
+
@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(association_class_name)
@join_table = join_table
- @order = options[:order] || "t.#{@owner.class.primary_key}"
+ @order = options[:order] || "t.#{@association_class.primary_key}"
interpolate_sql_options!(options, :finder_sql, :delete_sql)
@finder_sql = options[:finder_sql] ||
"SELECT t.*, j.* FROM #{association_table_name} t, #{@join_table} j " +
- "WHERE t.#{@owner.class.primary_key} = j.#{@association_foreign_key} AND " +
+ "WHERE t.#{@association_class.primary_key} = j.#{@association_foreign_key} AND " +
"j.#{association_class_primary_key_name} = #{@owner.quoted_id} " +
(options[:conditions] ? " AND " + options[:conditions] : "") + " " +
"ORDER BY #{@order}"
@@ -105,4 +105,4 @@ module ActiveRecord
end
end
end
-end \ No newline at end of file
+end