Imports changes from Rails' revision r9057
| 1 | *SVN* | *SVN* | 1 |
|---|---|---|---|
| 2 | 2 | ||
* Migrations: create_table supports primary_key_prefix_type. #10314 [student, thechrisoshow] | 3 | ||
| 4 | |||
| 3 | * Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle] | * Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle] | 5 |
| 4 | 6 | ||
| 5 | * Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews] | * Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews] | 7 |
| 966 | end | end | 966 |
|---|---|---|---|
| 967 | 967 | ||
| 968 | def reset_primary_key #:nodoc: | def reset_primary_key #:nodoc: | 968 |
key = get_primary_key(base_class.name) | 969 | ||
set_primary_key(key) | 970 | ||
key | 971 | ||
end | 972 | ||
| 973 | |||
def get_primary_key(base_name) #:nodoc: | 974 | ||
| 969 | key = 'id' | key = 'id' | 975 |
| 970 | case primary_key_prefix_type | case primary_key_prefix_type | 976 |
| 971 | when :table_name | when :table_name | 977 |
| 972 | key = Inflector.foreign_key(base_class.name, false) | key = Inflector.foreign_key(base_name, false) | 978 |
| 973 | when :table_name_with_underscore | when :table_name_with_underscore | 979 |
| 974 | key = Inflector.foreign_key(base_class.name) | key = Inflector.foreign_key(base_name) | 980 |
| 975 | end | end | 981 |
| 976 | set_primary_key(key) | ||
| 977 | key | key | 982 |
| 978 | end | end | 983 |
| 979 | 984 |
| 89 | # See also TableDefinition#column for details on how to create columns. | # See also TableDefinition#column for details on how to create columns. | 89 |
|---|---|---|---|
| 90 | def create_table(table_name, options = {}) | def create_table(table_name, options = {}) | 90 |
| 91 | table_definition = TableDefinition.new(self) | table_definition = TableDefinition.new(self) | 91 |
| 92 | table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false | table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false | 92 |
| 93 | 93 | ||
| 94 | yield table_definition | yield table_definition | 94 |
| 95 | 95 |