Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit ac4e7ff7b98f3c203a9f357415a3b926297d3c54 1 parent c24a35a
@jwood authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.