Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test-case to regressions on uniq hmt with default_scope order.

refs #5701
  • Loading branch information...
commit a0ec3c455759adcd6479c639a7fb91f0336d31e0 1 parent bcf0e08
@senny authored
View
5 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -901,4 +901,9 @@ def test_has_many_through_with_polymorphic_source
readers(:michael_authorless).update(first_post_id: 1)
assert_equal [posts(:thinking)], person.reload.first_posts
end
+
+ test "has many through with default order scope on the target" do
+ author = authors(:bob)
+ assert_equal [posts(:misc_by_bob)], author.unique_categorized_posts_with_default_sort
+ end
end
View
2  activerecord/test/models/author.rb
@@ -68,6 +68,7 @@ class Author < ActiveRecord::Base
has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
has_many :categorizations
+ has_many :ordered_categorizations, :class_name => 'OrderedCategorization'
has_many :categories, :through => :categorizations
has_many :named_categories, :through => :categorizations
@@ -79,6 +80,7 @@ class Author < ActiveRecord::Base
has_many :categorized_posts, :through => :categorizations, :source => :post
has_many :unique_categorized_posts, -> { uniq }, :through => :categorizations, :source => :post
+ has_many :unique_categorized_posts_with_default_sort, -> { uniq }, through: :ordered_categorizations, source: :default_scope_post
has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
View
8 activerecord/test/models/categorization.rb
@@ -17,3 +17,11 @@ class SpecialCategorization < ActiveRecord::Base
belongs_to :author
belongs_to :category
end
+
+class OrderedCategorization < ActiveRecord::Base
+ self.table_name = 'categorizations'
+ default_scope { order('categorizations.category_id') }
+
+ belongs_to :default_scope_post, foreign_key: :post_id, class_name: 'PostWithDefaultScope'
+ belongs_to :author
+end
Please sign in to comment.
Something went wrong with that request. Please try again.