Skip to content

Commit

Permalink
fix has_many :through in combination with :uniq for Postgres and SQ…
Browse files Browse the repository at this point in the history
…Lite3

These databases quote table names with double quotes instead of backticks.

closes mislav#24
  • Loading branch information
kjg authored and mislav committed Jul 7, 2010
1 parent d1a2519 commit 470dae1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/will_paginate/finder.rb
Expand Up @@ -198,7 +198,7 @@ def wp_count(options, args, finder)

if options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
# Remove quoting and check for table_name.*-like statement.
if options[:select].gsub('`', '') =~ /\w+\.\*/
if options[:select].gsub(/[`"]/, '') =~ /\w+\.\*/
options[:select] = "DISTINCT #{klass.table_name}.#{klass.primary_key}"
end
else
Expand Down
7 changes: 7 additions & 0 deletions test/finder_test.rb
Expand Up @@ -469,5 +469,12 @@ def test_hmt_with_include

# I cannot reproduce any of the failures from those reports :(
end

def test_hmt_with_uniq
project = Project.find(1)
result = project.unique_replies.paginate :page => 1, :per_page => 1,
:order => 'replies.id'
assert_equal replies(:decisive), result.first
end
end
end
2 changes: 2 additions & 0 deletions test/fixtures/project.rb
Expand Up @@ -12,4 +12,6 @@ def find_recent(params = {})
end
end
end

has_many :unique_replies, :through => :topics, :source => :replies, :uniq => true
end

0 comments on commit 470dae1

Please sign in to comment.