This project is archived and is in readonly mode.

#872 ✓committed
Morgan Schweers

:table_name_with_underscore behavior is inconsistent between migrations and find.

Reported by Morgan Schweers | August 20th, 2008 @ 08:04 PM | in 2.3.4


In schema_statements.rb#create_table it defines the primary key using the table name as the base name.

If we posit an accounts table, using :table_name_with_underscore, this means it will create a primary key of (for example) accounts_id.

When actually referencing that table from an ActiveRecord object, via Account.find(1) it will fail, because it is trying to use a primary key based off the class name, which is singular, and so will do a select for account_id.

I believe the singular is what most folks would expect the table name to come out as (accounts table has an account_id as the primary key), but one way or another the two portions are inconsistent.

Here's a shot at a patch, including fixes for the two migrations tests that use that feature. One thing I'm not sure of is if this patch needs to take into account the table pluralization setting.

I'm throwing this over to Jeremy Kemper, as the last person to touch the line I've changed in create_table. My apologies if that's the wrong person.

-- Morgan Schweers

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket