diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-16 18:28:03 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-16 18:28:03 -0200 |
commit | c069e0fa342c914901d23b6e9201f1bef168278b (patch) | |
tree | faaaa42a2ce98d5ec2c902c77b344eaf17a34c55 /activerecord/lib | |
parent | 17a0b733fd976d826dfd023992e2f082c4deb136 (diff) | |
parent | 02ca5580bd5f70dbd5ffcd147da6b99e2c90c265 (diff) | |
download | rails-c069e0fa342c914901d23b6e9201f1bef168278b.tar.gz rails-c069e0fa342c914901d23b6e9201f1bef168278b.tar.bz2 rails-c069e0fa342c914901d23b6e9201f1bef168278b.zip |
Merge pull request #12918 from versioncontrol/rails-12866
Checks to see if the record contains the foreign_key to set the inverse automatically
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index e6a45487d0..02f45731c9 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -226,7 +226,12 @@ module ActiveRecord # Returns true if inverse association on the given record needs to be set. # This method is redefined by subclasses. def invertible_for?(record) - inverse_reflection_for(record) + foreign_key_for?(record) && inverse_reflection_for(record) + end + + # Returns true if record contains the foreign_key + def foreign_key_for?(record) + record.attributes.has_key? reflection.foreign_key end # This should be implemented to return the values of the relevant key(s) on the owner, |