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') 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 From 2f0acf6a0a82e60d670b90d39d1278c55fdfe766 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 4 Apr 2013 17:59:02 -0400 Subject: use | to have more intent revealing code thanks to @egilburg for suggestion --- activerecord/lib/active_record/associations/association_scope.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index b62a16ea3f..aa5551fe0c 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -101,7 +101,7 @@ module ActiveRecord scope.includes! item.includes_values scope.where_values += item.where_values - scope.order_values += (item.order_values - scope.order_values) + scope.order_values |= item.order_values end end -- cgit v1.2.3