diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index bb1c705913d..80218b90701 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,8 @@ *CVS* +* Fixed has_and_belongs_to_many guessing of foreign key so that keys are generated correctly for models like SomeVerySpecialClient + [Florian Weber] + * Added counter_sql option for has_many associations [bitsweat]. Documentation: :counter_sql - specify a complete SQL statement to fetch the size of the association. If +:finder_sql+ is 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 fd36352deb2..8dec71403cd 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 @@ -4,7 +4,7 @@ module ActiveRecord 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.downcase)) + "_id" + @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}"