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...
1 parent 011baa0 commit d0bdff0799a4e6c6752fca56e69fd8b529117768 Morgan Schweers committed with jeremy Aug 20, 2008
@@ -99,7 +99,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
@@ -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 d0bdff0

Please sign in to comment.