mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
doc: ActiveRecord::Reflection::AssociationReflection#through_reflection
Added documentation demonstrating the use of #through_reflection for finding intervening reflection objects for HasManyThrough and HasOneThrough.
This commit is contained in:
parent
405de50af0
commit
f81d771f06
1 changed files with 11 additions and 0 deletions
|
@ -153,6 +153,17 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the AssociationReflection object specified in the <tt>:through</tt> option
|
||||||
|
# of a HasMantThrough or HasOneThrough association. Example:
|
||||||
|
#
|
||||||
|
# class Post < ActiveRecord::Base
|
||||||
|
# has_many :taggings
|
||||||
|
# has_many :tags, :through => :taggings
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# tags_reflection = Post.reflect_on_association(:tags)
|
||||||
|
# taggings_reflection = tags_reflection.through_reflection
|
||||||
|
#
|
||||||
def through_reflection
|
def through_reflection
|
||||||
@through_reflection ||= options[:through] ? active_record.reflect_on_association(options[:through]) : false
|
@through_reflection ||= options[:through] ? active_record.reflect_on_association(options[:through]) : false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue