1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

[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

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