Changeset 9056
- Timestamp:
- 03/18/08 18:23:14 (6 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (modified) (1 diff)
- trunk/activerecord/test/cases/migration_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r9050 r9056 1 1 *SVN* 2 3 * Migrations: create_table supports primary_key_prefix_type. #10314 [student, thechrisoshow] 2 4 3 5 * Added logging for dependency load errors with fixtures #11056 [stuthulhu] trunk/activerecord/lib/active_record/base.rb
r9023 r9056 975 975 976 976 def reset_primary_key #:nodoc: 977 key = get_primary_key(base_class.name) 978 set_primary_key(key) 979 key 980 end 981 982 def get_primary_key(base_name) #:nodoc: 977 983 key = 'id' 978 984 case primary_key_prefix_type 979 985 when :table_name 980 key = Inflector.foreign_key(base_ class.name, false)986 key = Inflector.foreign_key(base_name, false) 981 987 when :table_name_with_underscore 982 key = Inflector.foreign_key(base_class.name) 983 end 984 set_primary_key(key) 988 key = Inflector.foreign_key(base_name) 989 end 985 990 key 986 991 end trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
r9014 r9056 90 90 def create_table(table_name, options = {}) 91 91 table_definition = TableDefinition.new(self) 92 table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false92 table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false 93 93 94 94 yield table_definition trunk/activerecord/test/cases/migration_test.rb
r9003 r9056 181 181 Person.connection.drop_table :testings rescue nil 182 182 end 183 184 def test_create_table_with_primary_key_prefix_as_table_name_with_underscore 185 ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore 186 187 Person.connection.create_table :testings do |t| 188 t.column :foo, :string 189 end 190 191 assert_equal %w(foo testings_id), Person.connection.columns(:testings).map { |c| c.name }.sort 192 ensure 193 Person.connection.drop_table :testings rescue nil 194 ActiveRecord::Base.primary_key_prefix_type = nil 195 end 196 197 def test_create_table_with_primary_key_prefix_as_table_name 198 ActiveRecord::Base.primary_key_prefix_type = :table_name 199 200 Person.connection.create_table :testings do |t| 201 t.column :foo, :string 202 end 203 204 assert_equal %w(foo testingsid), Person.connection.columns(:testings).map { |c| c.name }.sort 205 ensure 206 Person.connection.drop_table :testings rescue nil 207 ActiveRecord::Base.primary_key_prefix_type = nil 208 end 209 183 210 184 211 # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL