Skip to content

Commit

Permalink
use rails4 join table naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
burnt43 committed Sep 16, 2015
1 parent e28969c commit fc4ccf5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/mini_record/auto_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,14 @@ class << connection; attr_accessor :table_definition; end unless connection.resp
table = if name = association.options[:join_table]
name.to_s
else
[table_name, association.name.to_s].sort.join("_")
association_table_name = association.name.to_s.classify.constantize.table_name
table_name_substrings = [table_name,association_table_name].collect { |string| string.split('_') }
common_substrings = Array.new
table_name_substrings.first.each_index { |i| table_name_substrings.first[i] == table_name_substrings.last[i] ? common_substrings.push(table_name_substrings.first[i]) : break }
common_prefix = common_substrings.join('_')
table_names = [table_name,association_table_name].sort
table_names.last.gsub!(/^#{common_prefix}_/,'')
table_names.join("_")
end
unless connection.tables.include?(table.to_s)
foreign_key = association.options[:foreign_key] || association.foreign_key
Expand Down

0 comments on commit fc4ccf5

Please sign in to comment.