Permalink
Browse files

Fix that creating a table whose primary key prefix type is :table_nam…

…e generates an incorrectly pluralized primary key.

[#872 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
Morgan Schweers authored and jeremy committed Aug 20, 2008
1 parent 47f7c93 commit d2d464e26e9d41b7299675e145ae1455cce37dd4
@@ -107,7 +107,7 @@ def columns(table_name, name = nil) end
# 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?
@@ -224,7 +224,7 @@ def test_create_table_with_primary_key_prefix_as_table_name_with_underscore
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 @@ def test_create_table_with_primary_key_prefix_as_table_name
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

0 comments on commit d2d464e

Please sign in to comment.