Cross-platform DISTINCT that doesn't work without surprises is a lost cause.

Implement this against the result if you desire.
This commit is contained in:
Ernie Miller 2011-06-10 11:32:29 -04:00
parent 2cfa803111
commit 567c70bd01
3 changed files with 2 additions and 10 deletions

View File

@ -13,8 +13,7 @@ module Ransack
def evaluate(search, opts = {})
viz = Visitor.new
relation = @object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
@object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
end
def attribute_method?(str, klass = @klass)

View File

@ -11,8 +11,7 @@ module Ransack
def evaluate(search, opts = {})
viz = Visitor.new
relation = @object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
@object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
end
def attribute_method?(str, klass = @klass)

View File

@ -129,12 +129,6 @@ module Ransack
where.to_sql.should match /\("people"."name" = 'Ernie' OR "children_people"."name" = 'Ernie'\) AND \("people"."name" = 'Bert' OR "children_people"."name" = 'Bert'\)/
end
it 'returns distinct records when passed :distinct => true' do
search = Search.new(Person, :g => [{:m => 'or', :comments_body_cont => 'e', :articles_comments_body_cont => 'e'}])
search.result.should have(920).items
search.result(:distinct => true).should have(330).items
search.result.all.uniq.should eq search.result(:distinct => true).all
end
end
describe '#sorts=' do