diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-31 08:51:39 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-31 09:11:25 +0900 |
commit | aae8fd0e07a9e924838845c1b29960f598fc14f3 (patch) | |
tree | f691dd32b108be3ada163641e4923623e05f7174 /activerecord/lib/active_record/associations | |
parent | b89a3e7e638a50c648a17d09c48b49b707e1d90d (diff) | |
parent | 2e3bba3e3af8c41e833cced61f0449ad73c947cc (diff) | |
download | rails-aae8fd0e07a9e924838845c1b29960f598fc14f3.tar.gz rails-aae8fd0e07a9e924838845c1b29960f598fc14f3.tar.bz2 rails-aae8fd0e07a9e924838845c1b29960f598fc14f3.zip |
Merge pull request #35799 from leboshi/master
Fix callbacks on has_many :through associations
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 15 |
1 files changed, 4 insertions, 11 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 84a9797aa5..0d384950fe 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -57,21 +57,14 @@ module ActiveRecord @through_records[record.object_id] ||= begin ensure_mutable - through_record = through_association.build(*options_for_through_record) - through_record.send("#{source_reflection.name}=", record) + attributes = through_scope_attributes + attributes[source_reflection.name] = record + attributes[source_reflection.foreign_type] = options[:source_type] if options[:source_type] - if options[:source_type] - through_record.send("#{source_reflection.foreign_type}=", options[:source_type]) - end - - through_record + through_association.build(attributes) end end - def options_for_through_record - [through_scope_attributes] - end - def through_scope_attributes scope.where_values_hash(through_association.reflection.name.to_s). except!(through_association.reflection.foreign_key, |