rails/rails — Issue #3829: default id failed with user define combined primary key
Author: lazing
Created: 2011-12-02 06:30:39+00:00
State: open

having a table and Idea model

``` sql

CREATE TABLE `ideas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`activity_object_id` int(11) NOT NULL,
`product_id` int(11) DEFAULT NULL,
`state` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`summary` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci,
`created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` datetime DEFAULT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`,`created_at`),
KEY `index_ideas_on_activity_object_id` (`activity_object_id`),
KEY `index_ideas_on_product_id` (`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
/*!50100 PARTITION BY RANGE ( yearweek(created_at))
(PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */

```

``` ruby
create_table :ideas do |t|
t.references :activity_object, :null=>false
t.references :product
t.string :state, :null=>false
t.string :summary, :null=>false
t.text :description
t.timestamps
end

execute <<-SQL
ALTER TABLE ideas DROP PRIMARY KEY ,
ADD PRIMARY KEY ( id , created_at )
SQL

execute <<-SQL
ALTER TABLE ideas
PARTITION BY RANGE ( yearweek(created_at))
(PARTITION pmax VALUES LESS THAN MAXVALUE)
SQL
```

rails could not find the id be default
the solution is add following to the model

``` ruby
class Idea < ActiveRecord::Base
set_primary_key :id
end
```

is this the right solution or should be fixed?