aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association.rb
diff options
context:
space:
mode:
authorEdo Balvers <i@edo.me>2013-11-16 21:18:02 +0100
committerEdo Balvers <i@edo.me>2013-11-16 21:18:02 +0100
commit02ca5580bd5f70dbd5ffcd147da6b99e2c90c265 (patch)
treef0a96848b21fea2aa3eac07bd9e564ca5de77b11 /activerecord/lib/active_record/associations/association.rb
parent1dfe05f98eaa0b8067fa1dfd019d44c851879b22 (diff)
downloadrails-02ca5580bd5f70dbd5ffcd147da6b99e2c90c265.tar.gz
rails-02ca5580bd5f70dbd5ffcd147da6b99e2c90c265.tar.bz2
rails-02ca5580bd5f70dbd5ffcd147da6b99e2c90c265.zip
Checks to see if the record contains the foreign_key to set the inverse automatically
Diffstat (limited to 'activerecord/lib/active_record/associations/association.rb')
-rw-r--r--activerecord/lib/active_record/associations/association.rb7
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,