From 3acc5d6ef7b3f000d0c541b9dc2881a8b7f40f75 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 7 Sep 2017 07:33:38 +0900 Subject: `has_many :through` with unscope should affect to through scope The order of scope evaluation should be from through scope to the association's own scope. Otherwise the association's scope cannot affect to through scope. Fixes #13677. Closes #28449. --- activerecord/test/models/author.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 0a52cc5390..3371fcbfcc 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -40,6 +40,7 @@ class Author < ActiveRecord::Base class_name: "Post" has_many :comments_desc, -> { order("comments.id DESC") }, through: :posts, source: :comments + has_many :unordered_comments, -> { unscope(:order).distinct }, through: :posts_sorted_by_id_limited, source: :comments has_many :funky_comments, through: :posts, source: :comments has_many :ordered_uniq_comments, -> { distinct.order("comments.id") }, through: :posts, source: :comments has_many :ordered_uniq_comments_desc, -> { distinct.order("comments.id DESC") }, through: :posts, source: :comments -- cgit v1.2.3