DISTINCT should only be added if you are counting rows (no argument to count), prepending it to arbitrary expressions will produce unintended nonsense expressions
@bughit please provide an executable test case to reproduce the issue. You can use this script as a foundation. Such a script should be attached to every Active Record issue. It helps a great deal to communicate the problem.
It's been a month without feedback. If this is still an issue, please provide a test-case to reproduce so we can investigate further.
On a side note, this might be related to the revert in #14226
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
create_table :posts do |t|
create_table :comments do |t|
class Post < ActiveRecord::Base
class Comment < ActiveRecord::Base
class BugTest < Minitest::Test
assert_equal 2, Post.count('flag or null')
assert_equal 2, Post.eager_load(:comments).count('flag or null')
assert_equal 2, Post.includes(:comments).count('flag or null')
SELECT COUNT(DISTINCT flag or null) FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"
thanks for the reproduction.
@tenderlove is this caused by the same part that was messing with includes in #14226?
@senny sure looks like it, but since @bughit provided a script, you should be able to git bisect (after you remove all the Gemfile preamble junk)
This issue has been automatically marked as stale because it has not been commented on for at least
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
This issue has been automatically closed because of inactivity.