diff options
author | Jon Leighton <j@jonathanleighton.com> | 2013-06-09 01:58:42 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2013-06-09 01:58:42 -0700 |
commit | ae6e6d953084d1966e52cc06ffe24131f0115cc1 (patch) | |
tree | 67f5b924096f4733980bab74c43ab92e437bca36 /activerecord/lib/active_record/reflection.rb | |
parent | 8b82387c97e60faff77c3db30e53abf2f94450d0 (diff) | |
parent | d6b03a376787ec9c9e934e5688a38c576f2e39b7 (diff) | |
download | rails-ae6e6d953084d1966e52cc06ffe24131f0115cc1.tar.gz rails-ae6e6d953084d1966e52cc06ffe24131f0115cc1.tar.bz2 rails-ae6e6d953084d1966e52cc06ffe24131f0115cc1.zip |
Merge pull request #10886 from wangjohn/chnges_for_automatic_inverse_associations
Documentation and cleanup of automatic discovery of inverse associations
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 27aa20b6c0..2ba89b13b7 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -313,8 +313,7 @@ module ActiveRecord # and prevents this object from finding the inverse association # automatically in the future. def remove_automatic_inverse_of! - @automatic_inverse_of = nil - options[:automatic_inverse_of] = false + @automatic_inverse_of = false end def polymorphic_inverse_of(associated_class) @@ -449,15 +448,16 @@ module ActiveRecord # Checks to see if the reflection doesn't have any options that prevent # us from being able to guess the inverse automatically. First, the - # +automatic_inverse_of+ option cannot be set to false. Second, we must - # have +has_many+, +has_one+, +belongs_to+ associations. Third, we must - # not have options such as +:polymorphic+ or +:foreign_key+ which prevent us - # from correctly guessing the inverse association. + # <tt>inverse_of</tt> option cannot be set to false. Second, we must + # have <tt>has_many</tt>, <tt>has_one</tt>, <tt>belongs_to</tt> associations. + # Third, we must not have options such as <tt>:polymorphic</tt> or + # <tt>:foreign_key</tt> which prevent us from correctly guessing the + # inverse association. # # Anything with a scope can additionally ruin our attempt at finding an # inverse, so we exclude reflections with scopes. def can_find_inverse_of_automatically?(reflection) - reflection.options[:automatic_inverse_of] != false && + reflection.options[:inverse_of] != false && VALID_AUTOMATIC_INVERSE_MACROS.include?(reflection.macro) && !INVALID_AUTOMATIC_INVERSE_OPTIONS.any? { |opt| reflection.options[opt] } && !reflection.scope |