diff options
author | Ivan Antropov <antropov.ivan@gmail.com> | 2014-05-25 21:08:11 +0700 |
---|---|---|
committer | Ivan Antropov <antropov.ivan@gmail.com> | 2014-05-25 21:08:11 +0700 |
commit | 1e0130f7e0a27878dd78ed1335ae8e6fbc52397f (patch) | |
tree | c8c1a26814181cf6cfc1569c643b5567b0b6a5d2 /activerecord/lib | |
parent | f632f79b8dcd144408c66a544984b2ba9cf52f87 (diff) | |
download | rails-1e0130f7e0a27878dd78ed1335ae8e6fbc52397f.tar.gz rails-1e0130f7e0a27878dd78ed1335ae8e6fbc52397f.tar.bz2 rails-1e0130f7e0a27878dd78ed1335ae8e6fbc52397f.zip |
Add setting of FK for throgh associations while building
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index f8a85b8a6f..9de9875b38 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -84,6 +84,17 @@ module ActiveRecord raise HasManyThroughNestedAssociationsAreReadonly.new(owner, reflection) end end + + def build_record(attributes) + inverse = source_reflection.inverse_of + target = through_association.target + + if inverse && target && !target.is_a?(Array) + attributes[inverse.foreign_key] = target.id + end + + super(attributes) + end end end end |