diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-04-04 14:37:22 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-04-04 14:37:22 +0000 |
commit | 36b8073ff553e8939d78ca2371ffdec7eb8f8071 (patch) | |
tree | db61c081ffdbc5ae43426dbad23d5baa5bd2daf7 /activerecord/lib/active_record | |
parent | 50538fb524950798cd8896f693909bdbc620bd8e (diff) | |
download | rails-36b8073ff553e8939d78ca2371ffdec7eb8f8071.tar.gz rails-36b8073ff553e8939d78ca2371ffdec7eb8f8071.tar.bz2 rails-36b8073ff553e8939d78ca2371ffdec7eb8f8071.zip |
Make HABTM#create behave the same as << with after_add callbacks. Closes #11374 [freels]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9224 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 7 |
1 files changed, 3 insertions, 4 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 923fbd8522..b06b618d5a 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 @@ -148,15 +148,14 @@ module ActiveRecord end private - def create_record(attributes) + def create_record(attributes, &block) # Can't use Base.create because the foreign key may be a protected attribute. ensure_owner_is_not_new if attributes.is_a?(Array) attributes.collect { |attr| create(attr) } else - record = build(attributes) - yield(record) - record + load_target + build_record(attributes, &block) end end end |