diff options
author | Ryan Kerr <leboshi@gmail.com> | 2019-03-30 00:35:16 -0400 |
---|---|---|
committer | Ryan Kerr <leboshi@gmail.com> | 2019-03-30 00:37:08 -0400 |
commit | 2e3bba3e3af8c41e833cced61f0449ad73c947cc (patch) | |
tree | 40b89928e1a3d8463584ae293ea52e087aa806fb /activerecord/CHANGELOG.md | |
parent | 4e076b03b6312b928a845f9a31288d10d7243338 (diff) | |
download | rails-2e3bba3e3af8c41e833cced61f0449ad73c947cc.tar.gz rails-2e3bba3e3af8c41e833cced61f0449ad73c947cc.tar.bz2 rails-2e3bba3e3af8c41e833cced61f0449ad73c947cc.zip |
Fix callbacks on has_many :through associations (#33249)
When adding a child record via a has_many :through association,
build_through_record would previously build the join record, and then
assign the child record and source_type option to it. Because the
before_add and after_add callbacks are called as part of build, however,
this caused the callbacks to receive incomplete records, specifically
without the other end of the has_many :through association. Collecting
all attributes before building the join record ensures the callbacks
receive the fully constructed record.
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 690d487a09..21861ced31 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Assign all attributes before calling `build` to ensure the child record is visible in + `before_add` and `after_add` callbacks for `has_many :through` associations. + + Fixes #33249. + + *Ryan H. Kerr* + * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation. ``` |