Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10314 (closed defect: fixed)

Opened 9 months ago

Last modified 3 months ago

create_table ignores primary_key_prefix_type

Reported by: student Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 1.2.3
Severity: normal Keywords:
Cc: thechrisoshow

Description

I have set config.active_record.primary_key_prefix_type = :table_name_with_underscore in config/environment.rb. ruby script/generate model foo bar:int baz:string rake db:migrate

Generates a table with id as the primary key. The easiest fix might be for generate model to insert :id => :foo_id into the create_table command.

Attachments

rails.diff (2.3 kB) - added by student on 12/03/07 17:03:00.
patch file vs 1.2.6
fix_for_create_table_with_primary_key_prefix.diff (3.2 kB) - added by thechrisoshow on 03/16/08 15:06:43.
This fixes the create_table with primary_key_prefix problems. (Also includes a couple of tests)
fix_for_create_table_with_primary_key_prefix.2.diff (3.2 kB) - added by thechrisoshow on 03/18/08 17:32:18.
Now patches cleanly against trunk

Change History

12/03/07 17:03:00 changed by student

  • attachment rails.diff added.

patch file vs 1.2.6

12/03/07 17:08:09 changed by student

  • milestone changed from 2.x to 2.0.

2.0 RC2 has no changes that should intersect this patch.

12/03/07 17:43:50 changed by mislav

  • summary changed from configactive_record.primary_key_prefix_type not propagating to database to create_table ignores primary_key_prefix_type.

Thanks for contributing, but this needs unit tests. Don't worry, it should also be simple. First checkout the Rails trunk with SVN and set up a database or two for testing. Then create a unit test for wanted behavior that fails without your fixes. Generate the patch for both tests and fixes by using svn diff.

12/05/07 21:38:28 changed by norbert

  • milestone changed from 2.0 to 2.x.

As stated in the description of report {68}, the 2.0 milestone should only be used by core members for real show stoppers.

03/16/08 15:06:43 changed by thechrisoshow

  • attachment fix_for_create_table_with_primary_key_prefix.diff added.

This fixes the create_table with primary_key_prefix problems. (Also includes a couple of tests)

03/16/08 15:31:51 changed by mislav

+1

03/17/08 14:40:59 changed by thechrisoshow

  • cc set to thechrisoshow.

03/18/08 17:32:18 changed by thechrisoshow

  • attachment fix_for_create_table_with_primary_key_prefix.2.diff added.

Now patches cleanly against trunk

03/18/08 18:24:05 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [9056]) Migrations: create_table supports primary_key_prefix_type. Closes #10314.

03/18/08 18:36:20 changed by bitsweat

(In [9057]) Merge [9056] from trunk: Migrations: create_table supports primary_key_prefix_type. References #10314.

04/08/08 19:01:31 changed by byrnejb

  • status changed from closed to reopened.
  • resolution deleted.

I have installed http://svn.rubyonrails.org/rails/branches/2-0-stable (r9125) into ventor/rails as an external. This is supposed to have this issue fixed per CS9057, however, given this config/environment.rb:

# Use table_id instead of id for primary key. config.active_record.primary_key_prefix_type = 'table_name_with_underscore'

and running rake db:drop; rake db:migrate with this migration:

class CreateEntities < ActiveRecord::Migration

def self.up

create_table :entities do |t|

t.string :entity_name, :null => false,

:limit => 40

t.string :entity_legal_name, :null => false,

:limit => 120

t.string :entity_legal_form, :null => false,

:limit => 4

t.timestamps

end

I get this sqlite3 schema as a result:

sqlite> .schema entities CREATE TABLE entities ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "entity_name" varchar(40) NOT NULL, "entity_legal_name" varchar(120) NOT NULL, "entity_legal_form" varchar(4) NOT NULL, "created_at" datetime DEFAULT NULL, "updated_at" datetime DEFAULT NULL);

I have confirmed that I am using the correct rails through the simple expedient of removing the rails gem. My application enviromnet is given below:

Ruby version 1.8.5 (i386-linux) RubyGems version 1.1.0 Rails version 2.0.2 Active Record version 2.0.2 Action Pack version 2.0.2 Active Resource version 2.0.2 Action Mailer version 2.0.2 Active Support version 2.0.2 Edge Rails revision 9243 Application root /home/byrnejb/Software/Development/Projects/proforma Environment development Database adapter sqlite3 Database schema version 41

04/08/08 19:04:43 changed by byrnejb

  • status changed from reopened to closed.
  • resolution set to fixed.

Ah. This fix requires that the argument to:

config.active_record.primary_key_prefix_type =

must be a symbol. A string value fails. Is this intentional?

05/23/08 19:16:31 changed by student

It matches AWDwR.