diff options
author | Steven Soroka <ssoroka78@gmail.com> | 2008-05-01 14:09:12 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-05-01 14:22:55 -0500 |
commit | 9c20391bbe6ec1c56f8c8ed4aefb31a93576f76a (patch) | |
tree | fb66a893a06c0a0f452748d808f10a5d74faf61f | |
parent | c353794dff580c8aa63b357b2857c1fadff3104b (diff) | |
download | rails-9c20391bbe6ec1c56f8c8ed4aefb31a93576f76a.tar.gz rails-9c20391bbe6ec1c56f8c8ed4aefb31a93576f76a.tar.bz2 rails-9c20391bbe6ec1c56f8c8ed4aefb31a93576f76a.zip |
best solution?
Signed-off-by: Steven Soroka <ssoroka78@gmail.com>
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 12 |
2 files changed, 14 insertions, 2 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 ebea313c18..f683669615 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -10,14 +10,14 @@ module ActiveRecord def create!(attrs = nil) @reflection.klass.transaction do - self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! }) + self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! } : @reflection.klass.create!) object end end def create(attrs = nil) @reflection.klass.transaction do - self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create }) + self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create } : @reflection.klass.create) object end end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index a9899102d7..e297447c88 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -115,6 +115,18 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb") end + def test_associate_with_create_and_no_options + peeps = posts(:thinking).people.count + posts(:thinking).people.create + assert_equal peeps + 1, posts(:thinking).people.count + end + + def test_associate_with_create_exclaimation_and_no_options + peeps = posts(:thinking).people.count + posts(:thinking).people.create! + assert_equal peeps + 1, posts(:thinking).people.count + end + def test_clear_associations assert_queries(2) { posts(:welcome);posts(:welcome).people(true) } |