Permalink
Browse files

Bug in has_many_through_association and foreign key names

  • Loading branch information...
1 parent 89f9202 commit 59f90149c6f7f3ab3fb3d55be503843260bb19f8 Elad Meidar committed Mar 4, 2010
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/indexer.rb
View
@@ -56,7 +56,15 @@ def self.check_for_indexes(migration_format = false)
when :has_and_belongs_to_many
table_name = reflection_options.options[:join_table] ||= [class_name.table_name, reflection_name.to_s].sort.join('_')
association_foreign_key = reflection_options.options[:association_foreign_key] ||= "#{reflection_name.to_s.singularize}_id"
- foreign_key = reflection_options.options[:foreign_key] ||= "#{class_name.name.tableize.singularize}_id"
+
+ # Guess foreign key?
+ if reflection_options.options[:foreign_key]
+ foreign_key = reflection_options.options[:foreign_key]
+ elsif reflection_options.options[:class_name]
+ foreign_key = reflection_options.options[:class_name].foreign_key
+ else
+ foreign_key = "#{class_name.name.tableize.singularize}_id"
+ end
composite_keys = [association_foreign_key, foreign_key]

0 comments on commit 59f9014

Please sign in to comment.