From d2d464e26e9d41b7299675e145ae1455cce37dd4 Mon Sep 17 00:00:00 2001 From: Morgan Schweers Date: Wed, 20 Aug 2008 11:32:20 -0700 Subject: Fix that creating a table whose primary key prefix type is :table_name generates an incorrectly pluralized primary key. [#872 state:committed] Signed-off-by: Jeremy Kemper --- .../active_record/connection_adapters/abstract/schema_statements.rb | 2 +- activerecord/test/cases/migration_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 2473c772e3..94d15fdb69 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -107,7 +107,7 @@ module ActiveRecord # See also TableDefinition#column for details on how to create columns. def create_table(table_name, options = {}) table_definition = TableDefinition.new(self) - table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false + table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false yield table_definition if block_given? diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index f0f21615e0..332a23a2ce 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -224,7 +224,7 @@ if ActiveRecord::Base.connection.supports_migrations? t.column :foo, :string end - assert_equal %w(foo testings_id), Person.connection.columns(:testings).map { |c| c.name }.sort + assert_equal %w(foo testing_id), Person.connection.columns(:testings).map { |c| c.name }.sort ensure Person.connection.drop_table :testings rescue nil ActiveRecord::Base.primary_key_prefix_type = nil @@ -237,7 +237,7 @@ if ActiveRecord::Base.connection.supports_migrations? t.column :foo, :string end - assert_equal %w(foo testingsid), Person.connection.columns(:testings).map { |c| c.name }.sort + assert_equal %w(foo testingid), Person.connection.columns(:testings).map { |c| c.name }.sort ensure Person.connection.drop_table :testings rescue nil ActiveRecord::Base.primary_key_prefix_type = nil -- cgit v1.2.3