From 8a3895bb9843482788447c34a313c321c4f2a240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 13 Jun 2014 19:34:20 -0300 Subject: [PATCH] Merge pull request #15701 from zzak/issue_15496 Open extension point for defining options in build_through_record --- .../associations/has_many_through_association.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 7c2868fe20f6b..d5016211be35c 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -84,12 +84,16 @@ def build_through_record(record) @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