aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-04-10 17:43:59 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-04-10 17:44:32 -0300
commita7a180bd8158a0a2151f0711b874a7495820d6e0 (patch)
tree826babcdecdf06bda24b56b10543422596d9140c /activerecord/lib/active_record/associations
parent632d9d22375dd79614ce731eb42875b65112b987 (diff)
parentec0928076529e8f0b5a4ad58c95cfa1fe6ed5b60 (diff)
downloadrails-a7a180bd8158a0a2151f0711b874a7495820d6e0.tar.gz
rails-a7a180bd8158a0a2151f0711b874a7495820d6e0.tar.bz2
rails-a7a180bd8158a0a2151f0711b874a7495820d6e0.zip
Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548
Fix insertion of records for hmt association with scope Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb6
1 files changed, 5 insertions, 1 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 64bc98c642..c2eff0d8ce 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -83,12 +83,16 @@ module ActiveRecord
@through_records[record.object_id] ||= begin
ensure_mutable
- through_record = through_association.build
+ through_record = through_association.build through_scope_attributes
through_record.send("#{source_reflection.name}=", record)
through_record
end
end
+ def through_scope_attributes
+ scope.where_values_hash(through_association.reflection.name.to_s)
+ end
+
def save_through_record(record)
build_through_record(record).save!
ensure