[skip ci] Doc improvement was added

This commit is contained in:
Aleksey Slivka 2018-03-22 14:47:41 +03:00
parent 49d3b70a59
commit cbe4e04026
1 changed files with 14 additions and 0 deletions

View File

@ -513,6 +513,20 @@ def index
end 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 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, 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 which is potentially slower and uses more memory, and that it may display