TrestleAdmin / trestle-search

Search plugin for the Trestle admin framework
https://trestle.io
GNU Lesser General Public License v3.0
28 stars 11 forks source link

search query scope #23

Closed petitkriket closed 4 years ago

petitkriket commented 4 years ago

As in the docs, I set a scope like

In Company.rb model

scope :staff_between, ->(from, to) { joins(:job_histories).group('companies.id').having("count(company_id) >= :from AND count(comapny_id) <= :to", from: from, to: to) }

so I can call inside companies_admin.rb scope :small, -> { Company.staff_between(1, 10) }, label: "1 to 25 collaborators"

But the group() creates an unexpected bahaviour when the results are counted at display Screenshot_20200502_143929

Is there a way to circumvent that ? the count done to return the badge number gives an hash of results instead

petitkriket commented 4 years ago

Used Rails Counter Cache feature, working as expected