This project is archived and is in readonly mode.
: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
Greetings,
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
-
josh November 22nd, 2008 @ 07:02 PM
- State changed from new to stale
Staling out, let me know if its still an issue.
-
Todd Hanson February 20th, 2009 @ 09:26 PM
- Title changed from :table_name_with_underscore behavior is inconsistent between migrations and find. to still an issue
both 2.1.2 and 2.2.2 are affected
-
Todd Hanson February 20th, 2009 @ 09:27 PM
- Title changed from still an issue to :table_name_with_underscore behavior is inconsistent between migrations and find.
sorry, didn't mean to change the title.
-
josh February 20th, 2009 @ 10:31 PM
- State changed from stale to open
-
Mike Breen August 10th, 2009 @ 12:49 AM
- Tag changed from 2.1, activerecord, bug, edge, patch to 2.1, activerecord, bug, bugmash, edge, patch
+1 verified that the patch applies cleanly to 2-3-stable. The supplied tests will fail without the included changes.
-
Jeremy Kemper August 10th, 2009 @ 05:59 AM
- Tag changed from 2.1, activerecord, bug, bugmash, edge, patch to 2.1, activerecord, bug, edge, patch
- Milestone changed from 2.x to 2.3.4
-
Repository August 10th, 2009 @ 06:01 AM
- State changed from open to committed
(from [d0bdff0799a4e6c6752fca56e69fd8b529117768]) 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 jeremy@bitsweat.net
http://github.com/rails/rails/commit/d0bdff0799a4e6c6752fca56e69fd8... -
Repository August 10th, 2009 @ 06:01 AM
(from [d2d464e26e9d41b7299675e145ae1455cce37dd4]) 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 jeremy@bitsweat.net
http://github.com/rails/rails/commit/d2d464e26e9d41b7299675e145ae14...
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 872 :table_name_with_underscore behavior is inconsistent between migrations and find. [#872 state:committed]
- 872 :table_name_with_underscore behavior is inconsistent between migrations and find. [#872 state:committed]