Method: Extlib::Inflection.foreign_key

Defined in:
lib/extlib/inflection.rb

.foreign_key(class_name, key = "id") ⇒ Object

Creates a foreign key name from a class name.

Examples:

"Message".foreign_key #=> "message_id"
"Admin::Post".foreign_key #=> "post_id"


87
88
89
# File 'lib/extlib/inflection.rb', line 87

def foreign_key(class_name, key = "id")
  underscore(demodulize(class_name.to_s)) << "_" << key.to_s
end