Forum: Ruby on Rails HABTM Duplicate entry error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Afd161fd1de4b33cc074621572b41f0f?d=identicon&s=25 Jables (Guest)
on 2009-03-31 01: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,
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
Afd161fd1de4b33cc074621572b41f0f?d=identicon&s=25 unknown (Guest)
on 2009-03-31 03: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.