aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorrailsbob <anup.narkhede@gmail.com>2009-08-08 23:48:11 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-09 18:44:45 -0700
commite06a0b03c8ba29f4b05a35560645814ac88aefbe (patch)
tree862f05ab08f35a7ad7aaeaa17490de4df5cb84c4 /activerecord/lib/active_record/associations
parente4ceea3795ecc7adcec28a1b9d63782be1401256 (diff)
downloadrails-e06a0b03c8ba29f4b05a35560645814ac88aefbe.tar.gz
rails-e06a0b03c8ba29f4b05a35560645814ac88aefbe.tar.bz2
rails-e06a0b03c8ba29f4b05a35560645814ac88aefbe.zip
has_many :through create should not raise validation errors
[#2934 state:committed] 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_many_through_association.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index f4507c979c..292da58831 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -20,7 +20,11 @@ module ActiveRecord
ensure_owner_is_not_new
transaction do
- self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.create_association } : @reflection.create_association)
+ object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.create_association } : @reflection.create_association
+ raise_on_type_mismatch(object)
+ add_record_to_target_with_callbacks(object) do |r|
+ insert_record(object, false)
+ end
object
end
end