From cbe4e04026ed1f92ef71bc778e001cf209419dbc Mon Sep 17 00:00:00 2001 From: Aleksey Slivka Date: Thu, 22 Mar 2018 14:47:41 +0300 Subject: [PATCH] [skip ci] Doc improvement was added --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index db1197c..653561a 100644 --- a/README.md +++ b/README.md @@ -513,6 +513,20 @@ def index end ``` +Yet another mehtod to solve such problem with Postgresql is to use ActiveRecords`s `.includes` in combination with `.group` instead of `distinct: true`. + +For example: +```ruby +def index + @q = Person.ransack(params[:q]) + @people = @q.result + .group('persons.id') + .includes(:articles) + .page(params[:page]) +end + +``` + A final way of last resort is to call `to_a.uniq` on the collection at the end with the caveat that the de-duping is taking place in Ruby instead of in SQL, which is potentially slower and uses more memory, and that it may display