aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorJaime Bellmyer <online@bellmyer.com>2009-02-26 09:48:58 -0600
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-09 22:17:39 -0700
commitf0602214e0ff4638fafb819a7ffbd4ce0e37efb7 (patch)
treed9c6e56dae0cf5c0a34deec95523c06d2a2fc372 /activerecord/lib/active_record/associations
parentd2d464e26e9d41b7299675e145ae1455cce37dd4 (diff)
downloadrails-f0602214e0ff4638fafb819a7ffbd4ce0e37efb7.tar.gz
rails-f0602214e0ff4638fafb819a7ffbd4ce0e37efb7.tar.bz2
rails-f0602214e0ff4638fafb819a7ffbd4ce0e37efb7.zip
raises exception (ActiveRecord::ConfigurationError with message) on habtm association creation if join table contains a primary key
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
index fd23e59e82..b5d8de2544 100644
--- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -29,6 +29,10 @@ module ActiveRecord
end
def insert_record(record, force = true, validate = true)
+ if ActiveRecord::Base.connection.supports_primary_key? && ActiveRecord::Base.connection.primary_key(@reflection.options[:join_table])
+ raise ActiveRecord::ConfigurationError, "Primary key is not allowed in a has_and_belongs_to_many join table (#{@reflection.options[:join_table]})."
+ end
+
if record.new_record?
if force
record.save!