diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-04 15:43:02 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-04 15:43:02 -0700 |
commit | 507812fdf32586a59071efabdfc471402bd589f3 (patch) | |
tree | 530e01dc8f7c408d1fd4131a8b2caaa7b884578c | |
parent | f28345858ae523845c888fec29865ef2a8f0a68a (diff) | |
parent | 261520d91890a6844fc769ecf8bd221e35c8974c (diff) | |
download | rails-507812fdf32586a59071efabdfc471402bd589f3.tar.gz rails-507812fdf32586a59071efabdfc471402bd589f3.tar.bz2 rails-507812fdf32586a59071efabdfc471402bd589f3.zip |
Merge pull request #10094 from neerajdotname/fix2
Collection of small fixes. Check individual commits for background.
4 files changed, 23 insertions, 5 deletions
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 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 + # #=> [<ActiveRecord::Reflection::ThroughReflection: @macro=:has_many, @name=:tags, @options={:through=>:taggings}, @active_record=Post>, + # <ActiveRecord::Reflection::AssociationReflection: @macro=:has_many, @name=:taggings, @options={}, @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 <tt>:through</tt> source reflection names: + # Gets an array of possible <tt>:through</tt> 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 } diff --git a/guides/bug_report_templates/active_record_gem.rb b/guides/bug_report_templates/active_record_gem.rb index 19b7309dd7..2c63342572 100644 --- a/guides/bug_report_templates/active_record_gem.rb +++ b/guides/bug_report_templates/active_record_gem.rb @@ -25,7 +25,7 @@ class Comment < ActiveRecord::Base belongs_to :post end -class HasManyBugTest < MiniTest::Unit::TestCase +class BugTest < MiniTest::Unit::TestCase def test_association_stuff post = Post.create! post.comments << Comment.create! diff --git a/guides/bug_report_templates/active_record_master.rb b/guides/bug_report_templates/active_record_master.rb index 99107b83cf..68069cdd8d 100644 --- a/guides/bug_report_templates/active_record_master.rb +++ b/guides/bug_report_templates/active_record_master.rb @@ -36,7 +36,7 @@ class Comment < ActiveRecord::Base belongs_to :post end -class HasManyBugTest < MiniTest::Unit::TestCase +class BugTest < MiniTest::Unit::TestCase def test_association_stuff post = Post.create! post.comments << Comment.create! |