diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-11 20:15:53 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-11 20:15:53 -0700 |
commit | 98ade30e421e2c9e405060bba87ecbd092f11698 (patch) | |
tree | 47e0359fb71bbd7432c743f4798261ed8072bef7 /activerecord/lib/active_record/associations.rb | |
parent | d9e8ec61a4988f3836d8c6aa830b6ffd6a3a940a (diff) | |
parent | 346cda4f348993b45a894c1351e2cca03d72dee2 (diff) | |
download | rails-98ade30e421e2c9e405060bba87ecbd092f11698.tar.gz rails-98ade30e421e2c9e405060bba87ecbd092f11698.tar.bz2 rails-98ade30e421e2c9e405060bba87ecbd092f11698.zip |
Merge pull request #10574 from wangjohn/automatic_inverse_of_documentation
Adding documentation to the automatic inverse_of finder.
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 5e5995f566..b71200cd2a 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -568,6 +568,8 @@ module ActiveRecord # @group.avatars << Avatar.new # this would work if User belonged_to Avatar rather than the other way around # @group.avatars.delete(@group.avatars.last) # so would this # + # == Setting Inverses + # # If you are using a +belongs_to+ on the join model, it is a good idea to set the # <tt>:inverse_of</tt> option on the +belongs_to+, which will mean that the following example # works correctly (where <tt>tags</tt> is a +has_many+ <tt>:through</tt> association): @@ -584,6 +586,25 @@ module ActiveRecord # belongs_to :tag, inverse_of: :taggings # end # + # If you do not set the +:inverse_of+ record, the association will do its + # best to match itself up with the correct inverse. Automatic +:inverse_of+ + # detection only works on :has_many, :has_one, and :belongs_to associations. + # + # Extra options on the associations, as defined in the + # +AssociationReflection::INVALID_AUTOMATIC_INVERSE_OPTIONS+ constant, will + # also prevent the association's inverse from being found automatically. + # + # The automatic guessing of the inverse association uses a heuristic based + # on the name of the class, so it may not work for all associations, + # especially the ones with non-standard names. + # + # You can turn off the automatic detection of inverse associations by setting + # the +:automatic_inverse_of+ option to +false+ like so: + # + # class Taggable < ActiveRecord::Base + # belongs_to :tag, automatic_inverse_of: false + # end + # # == Nested Associations # # You can actually specify *any* association with the <tt>:through</tt> option, including an |