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:
parent
2cfa803111
commit
567c70bd01
|
@ -13,8 +13,7 @@ module Ransack
|
||||||
|
|
||||||
def evaluate(search, opts = {})
|
def evaluate(search, opts = {})
|
||||||
viz = Visitor.new
|
viz = Visitor.new
|
||||||
relation = @object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
|
@object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
|
||||||
opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def attribute_method?(str, klass = @klass)
|
def attribute_method?(str, klass = @klass)
|
||||||
|
|
|
@ -11,8 +11,7 @@ module Ransack
|
||||||
|
|
||||||
def evaluate(search, opts = {})
|
def evaluate(search, opts = {})
|
||||||
viz = Visitor.new
|
viz = Visitor.new
|
||||||
relation = @object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
|
@object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
|
||||||
opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def attribute_method?(str, klass = @klass)
|
def attribute_method?(str, klass = @klass)
|
||||||
|
|
|
@ -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'\)/
|
where.to_sql.should match /\("people"."name" = 'Ernie' OR "children_people"."name" = 'Ernie'\) AND \("people"."name" = 'Bert' OR "children_people"."name" = 'Bert'\)/
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#sorts=' do
|
describe '#sorts=' do
|
||||||
|
|
Loading…
Reference in New Issue