Forum: Ruby on Rails HABTM Duplicate entry error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jables (Guest)
on 2009-03-31 03:29
(Received via mailing list)
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,

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!

unknown (Guest)
on 2009-03-31 05:00
(Received via mailing list)
Problem is solved!

FYI - in the migrations

create_table :tablename, :id => false

:id => false being the key there
This topic is locked and can not be replied to.