aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-06-13 15:30:40 -0700
committerZachary Scott <e@zzak.io>2014-06-13 15:30:40 -0700
commit715489965f9d5f5e86f64a29c122ffe3197aee2b (patch)
tree1543b356ceaa217f160398f2e0397ed091601904 /activerecord
parentf5ae87f8d689b474bf3e98f5014ba36ebd807367 (diff)
downloadrails-715489965f9d5f5e86f64a29c122ffe3197aee2b.tar.gz
rails-715489965f9d5f5e86f64a29c122ffe3197aee2b.tar.bz2
rails-715489965f9d5f5e86f64a29c122ffe3197aee2b.zip
Open extension point for defining options in build_through_record
This fixes #15496
Diffstat (limited to 'activerecord')
-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 da9b125fd6..f4c385ef1b 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -82,12 +82,16 @@ module ActiveRecord
@through_records[record.object_id] ||= begin
ensure_mutable
- through_record = through_association.build through_scope_attributes
+ through_record = through_association.build(*options_for_through_record)
through_record.send("#{source_reflection.name}=", record)
through_record
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)
end