Skip to content

Commit d2d464e

Browse files
Morgan Schweersjeremy
authored andcommitted
Fix that creating a table whose primary key prefix type is :table_name generates an incorrectly pluralized primary key.
[rails#872 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
1 parent 47f7c93 commit d2d464e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def columns(table_name, name = nil) end
107107
# See also TableDefinition#column for details on how to create columns.
108108
def create_table(table_name, options = {})
109109
table_definition = TableDefinition.new(self)
110-
table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false
110+
table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
111111

112112
yield table_definition if block_given?
113113

activerecord/test/cases/migration_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_create_table_with_primary_key_prefix_as_table_name_with_underscore
224224
t.column :foo, :string
225225
end
226226

227-
assert_equal %w(foo testings_id), Person.connection.columns(:testings).map { |c| c.name }.sort
227+
assert_equal %w(foo testing_id), Person.connection.columns(:testings).map { |c| c.name }.sort
228228
ensure
229229
Person.connection.drop_table :testings rescue nil
230230
ActiveRecord::Base.primary_key_prefix_type = nil
@@ -237,7 +237,7 @@ def test_create_table_with_primary_key_prefix_as_table_name
237237
t.column :foo, :string
238238
end
239239

240-
assert_equal %w(foo testingsid), Person.connection.columns(:testings).map { |c| c.name }.sort
240+
assert_equal %w(foo testingid), Person.connection.columns(:testings).map { |c| c.name }.sort
241241
ensure
242242
Person.connection.drop_table :testings rescue nil
243243
ActiveRecord::Base.primary_key_prefix_type = nil

0 commit comments

Comments
 (0)