diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-13 19:34:20 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-13 19:34:20 -0300 |
commit | 9f0cd30d90a8966011dbc655f81a365ad350819d (patch) | |
tree | 2d300a6fd779c505e0e2dc946e16934b9f7a573e /activerecord | |
parent | 2324495d5f39fbbb83e035bdc2210f46e9cbd6c6 (diff) | |
parent | 715489965f9d5f5e86f64a29c122ffe3197aee2b (diff) | |
download | rails-9f0cd30d90a8966011dbc655f81a365ad350819d.tar.gz rails-9f0cd30d90a8966011dbc655f81a365ad350819d.tar.bz2 rails-9f0cd30d90a8966011dbc655f81a365ad350819d.zip |
Merge pull request #15701 from zzak/issue_15496
Open extension point for defining options in build_through_record
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 6 |
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 1713ab7ed3..175019a72b 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 |