From 98e42bc37e866508a671b569d905852c2e6ae17e Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 4 Apr 2013 16:46:04 -0400 Subject: expanded rdoc for chain and reflection_names --- activerecord/lib/active_record/reflection.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/reflection.rb') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 2026511e38..3eee77e653 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -436,6 +436,17 @@ module ActiveRecord # The chain is built by recursively calling #chain on the source reflection and the through # reflection. The base case for the recursion is a normal association, which just returns # [self] as its #chain. + # + # class Post < ActiveRecord::Base + # has_many :taggings + # has_many :tags, through: :taggings + # end + # + # tags_reflection = Post.reflect_on_association(:tags) + # tags_reflection.chain + # #=> [:taggings}, @active_record=Post>, + # ] + # def chain @chain ||= begin chain = source_reflection.chain + through_reflection.chain @@ -506,9 +517,16 @@ module ActiveRecord source_reflection.options[:primary_key] || primary_key(klass || self.klass) end - # Gets an array of possible :through source reflection names: + # Gets an array of possible :through source reflection names in both singular and plural form. # - # [:singularized, :pluralized] + # class Post < ActiveRecord::Base + # has_many :taggings + # has_many :tags, through: :taggings + # end + # + # tags_reflection = Post.reflect_on_association(:tags) + # tags_reflection.source_reflection_names + # #=> [:tag, :tags] # def source_reflection_names @source_reflection_names ||= (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).collect { |n| n.to_sym } -- cgit v1.2.3