Skip to content

Commit

Permalink
Fix that creating a table whose primary key prefix type is :table_nam…
Browse files Browse the repository at this point in the history
…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 10, 2009
1 parent 011baa0 commit d0bdff0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d0bdff0

Please sign in to comment.