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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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> any ideas? > > Thanks, > JB > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4/21/08, Jables <brun3797-Meo6Lv8EUjg3uPMLIKxrzw@public.gmane.org> 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 Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
nevermind, figured it out: FYI the migration is create_table :genres_stories, :id => false do |t| t.references :story, :genre end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---