aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_through_association.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-08 21:51:33 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-08 21:51:33 +0100
commit761283ffdb5750f8a38e2ed67891d2b2b9152d7f (patch)
tree4df91ec28ab7d403174468a437c3fe28d7ff3925 /activerecord/lib/active_record/associations/has_many_through_association.rb
parent00544c778f53b034bf4560548479a20a06d5c22d (diff)
downloadrails-761283ffdb5750f8a38e2ed67891d2b2b9152d7f.tar.gz
rails-761283ffdb5750f8a38e2ed67891d2b2b9152d7f.tar.bz2
rails-761283ffdb5750f8a38e2ed67891d2b2b9152d7f.zip
Ensure hm:t#create/create! throws ActiveRecord::RecordNotSaved when the owner is new
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb4
1 files changed, 4 insertions, 0 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 e21ef90391..ed7c3a6e08 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -8,6 +8,8 @@ module ActiveRecord
alias_method :new, :build
def create!(attrs = nil)
+ ensure_owner_is_not_new
+
transaction do
self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.create_association! } : @reflection.create_association!)
object
@@ -15,6 +17,8 @@ module ActiveRecord
end
def create(attrs = nil)
+ ensure_owner_is_not_new
+
transaction do
self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.create_association } : @reflection.create_association)
object