As of 2.3.4 rails now raises an exception when habtm table
contains a primary key (see #2086 Primary key on HABTM join table now raises an exception).
However, on Postgresql, when used with Slony Replication (which
is a most popular replication tool), you have to have primary key
in order to replicate the table. While you can make a composite key
on habtm table, one of the options is to add a synthetic primary
key to the table, which was a standard approach with Slony for
quite some time now. This is what I had in my setup - multiple
replications set up on all of my applications with synthetic keys
for all habtm tables.
After upgrading to 2.3.4, they have all failed and I had to
manually edit has_and_belongs_to_many_association.rb to comment out
lines 42-45 to disable the check.
Now, while it is possible for me to alter all my database
schemes and redo the replication, it seems to me that for a minor
upgrade from 2.3.3 to 2.3.4, this is not the right way. May be it
is more appropriate to set up some sort of configuration key that
will allow to disable the check for those who really need now and
announce that it will not work anymore from version 3.0?
this is the code that I had commented out
if has_primary_key?
raise ActiveRecord::ConfigurationError, "Primary key is not allowed
in a has_and_belongs_to_many join table
(#{@reflection.options[:join_table]})." end