HABTM setup problem?

Hey,
So I have a HABTM relationship between story and genre with a join
table genres_stories. From what I can tell the first story I add
genres to works fine, but when I try to add genres to a second stroy I
get the following error:

PRIMARY KEY must be unique: INSERT INTO genres_stories (“genre_id”,
“story_id”, “id”) VALUES (1, 2, 1)

any ideas?

Thanks,
JB

On 21 Apr 2008, at 22:26, Jables wrote:

Hey,
So I have a HABTM relationship between story and genre with a join
table genres_stories. From what I can tell the first story I add
genres to works fine, but when I try to add genres to a second stroy I
get the following error:

PRIMARY KEY must be unique: INSERT INTO genres_stories (“genre_id”,
“story_id”, “id”) VALUES (1, 2, 1)

If you’ve got hatbm (as opposed to has many through) you don’t want an
id column.

Fred

On 4/21/08, Jables [email protected] wrote:

So I have a HABTM relationship between story and genre with a join
table genres_stories. From what I can tell the first story I add
genres to works fine, but when I try to add genres to a second stroy I
get the following error:

PRIMARY KEY must be unique: INSERT INTO genres_stories (“genre_id”,
“story_id”, “id”) VALUES (1, 2, 1)

any ideas?

A join table doesn’t typically require a primary key id field. If you
disagree then you at least need to base it on a sequence or some other
auto-incrementing feature of your database.


Greg D.
http://destiney.com/

So here is my migration:

    create_table :genres_stories, :force => true do |t|
      t.references :story, :genre
    end

it is automatically putting that id field into the table.

nevermind, figured it out:

FYI the migration is
create_table :genres_stories, :id => false do |t|
t.references :story, :genre
end