public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Merge [9056] from trunk: Migrations: create_table supports 
primary_key_prefix_type. References #10314.

git-svn-id: 
http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@9057 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jeremy (author)
Tue Mar 18 11:36:11 -0700 2008
commit  5a5b0b8b3be2e724520e0d1c6dea00c98d599165
tree    7f5df80c0d50c50c95ff78395bb0351ecd458133
parent  b96db528788c2a04ad43c30155d33034ab242212
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Migrations: create_table supports primary_key_prefix_type. #10314 [student, thechrisoshow]
0
+
0
 * Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle]
0
 
0
 * Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]
...
966
967
968
 
 
 
 
 
 
969
970
971
972
 
973
974
 
975
976
977
978
979
...
966
967
968
969
970
971
972
973
974
975
976
977
 
978
979
 
980
981
 
982
983
984
0
@@ -966,14 +966,19 @@
0
       end
0
 
0
       def reset_primary_key #:nodoc:
0
+ key = get_primary_key(base_class.name)
0
+ set_primary_key(key)
0
+ key
0
+ end
0
+
0
+ def get_primary_key(base_name) #:nodoc:
0
         key = 'id'
0
         case primary_key_prefix_type
0
           when :table_name
0
- key = Inflector.foreign_key(base_class.name, false)
0
+ key = Inflector.foreign_key(base_name, false)
0
           when :table_name_with_underscore
0
- key = Inflector.foreign_key(base_class.name)
0
+ key = Inflector.foreign_key(base_name)
0
         end
0
- set_primary_key(key)
0
         key
0
       end
0
 
...
89
90
91
92
 
93
94
95
...
89
90
91
 
92
93
94
95
0
@@ -89,7 +89,7 @@
0
       # See also TableDefinition#column for details on how to create columns.
0
       def create_table(table_name, options = {})
0
         table_definition = TableDefinition.new(self)
0
- table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
0
+ table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false
0
 
0
         yield table_definition
0
 

Comments

    No one has commented yet.