Changeset 9224
- Timestamp:
- 04/04/08 14:37:22 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
r8653 r9224 149 149 150 150 private 151 def create_record(attributes )151 def create_record(attributes, &block) 152 152 # Can't use Base.create because the foreign key may be a protected attribute. 153 153 ensure_owner_is_not_new … … 155 155 attributes.collect { |attr| create(attr) } 156 156 else 157 record = build(attributes) 158 yield(record) 159 record 157 load_target 158 build_record(attributes, &block) 160 159 end 161 160 end trunk/activerecord/test/cases/associations/callbacks_test.rb
r8681 r9224 95 95 end 96 96 97 def test_has_and_belongs_to_many_after_add_called_after_save 98 ar = projects(:active_record) 99 assert ar.developers_log.empty? 100 alice = Developer.new(:name => 'alice') 101 ar.developers_with_callbacks << alice 102 assert_equal"after_adding#{alice.id}", ar.developers_log.last 103 104 bob = ar.developers_with_callbacks.create(:name => 'bob') 105 assert_equal "after_adding#{bob.id}", ar.developers_log.last 106 107 ar.developers_with_callbacks.build(:name => 'charlie') 108 assert_equal "after_adding<new>", ar.developers_log.last 109 end 110 111 97 112 def test_has_and_belongs_to_many_remove_callback 98 113 david = developers(:david)