Created
September 29, 2013 06:07
-
-
Save bachue/6749798 to your computer and use it in GitHub Desktop.
原来ActiveRecord默认约定的join表名字是两个表哪个名字短哪个就排在前面啊
以前一直不知道的说
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generates a join table name from two provided table names. | |
# The names in the join table names end up in lexicographic order. | |
# | |
# join_table_name("members", "clubs") # => "clubs_members" | |
# join_table_name("members", "special_clubs") # => "members_special_clubs" | |
def join_table_name(first_table_name, second_table_name) | |
if first_table_name < second_table_name | |
join_table = "#{first_table_name}_#{second_table_name}" | |
else | |
join_table = "#{second_table_name}_#{first_table_name}" | |
end | |
model.table_name_prefix + join_table + model.table_name_suffix | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment