I have a model OrderUser and a model Venue, both are related through a HABTM to relationship and the join table is order_users_venues with the two foreign keys venue_id and order_user_id. I am trying to add venues to a user, it works fine if one user is doing this, but if another is it reinserts the same ids into the table and screws everything up: Mysql::Error: Duplicate entry ''1'' for key 1: INSERT INTO `order_users_venues` (`venue_id`, `id`, `order_user_id`) VALUES (1, 1, 2) This ''1'' is entry 3 in the table. Obviously I am not using HABTM correctly or am using it when it I shouldn''t be. Please advise! Thanks, John --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
brun3797-Meo6Lv8EUjg3uPMLIKxrzw@public.gmane.org
2009-Mar-31 00:59 UTC
Re: HABTM Duplicate entry error
Problem is solved! FYI - in the migrations create_table :tablename, :id => false :id => false being the key there On Mar 30, 4:28 pm, Jables <brun3...-Meo6Lv8EUjg3uPMLIKxrzw@public.gmane.org> wrote:> I have a model OrderUser and a model Venue, both are related through a > HABTM to relationship and the join table is order_users_venues with > the two foreign keys venue_id and order_user_id. I am trying to add > venues to a user, it works fine if one user is doing this, but if > another is it reinserts the same ids into the table and screws > everything up: > > Mysql::Error: Duplicate entry ''1'' for key 1: INSERT INTO > `order_users_venues` (`venue_id`, `id`, `order_user_id`) VALUES (1, 1, > 2) > > This ''1'' is entry 3 in the table. > > Obviously I am not using HABTM correctly or am using it when it I > shouldn''t be. > > Please advise! > > Thanks, > John--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---