Skip to content
Browse files

Use the unqualified class name to determine the name of the foreign key

  • Loading branch information...
1 parent c24a35a commit ac4e7ff7b98f3c203a9f357415a3b926297d3c54 @jwood committed Apr 4, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/tenacity/association.rb
View
8 lib/tenacity/association.rb
@@ -133,11 +133,15 @@ def qualified_const_get(clazz)
path.inject(Object) { |ns,name| ns.const_get(name) }
end
+ def unqualified_class_name(clazz)
+ clazz.to_s.split('::').last
+ end
+
def belongs_to_foreign_key
if polymorphic?
(name.to_s + "_id").to_sym
else
- @class_name.underscore + "_id"
+ unqualified_class_name(@class_name).underscore + "_id"
end
end
@@ -146,7 +150,7 @@ def has_x_foreign_key(clazz)
if polymorphic?
(@as.to_s + "_id").to_sym
else
- "#{ActiveSupport::Inflector.underscore(clazz)}_id"
+ "#{ActiveSupport::Inflector.underscore(unqualified_class_name(clazz))}_id"
end
end
end

0 comments on commit ac4e7ff

Please sign in to comment.
Something went wrong with that request. Please try again.