9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/tasks/otus/duplicates_controller.rb', line 9
def data
a = Otu
.joins(:taxon_name)
.where('otus.project_id = ?', sessions_current_project_id)
.select('otus.id, otus.name, taxon_names.type, taxon_names.cached, taxon_names.cached_author_year, count(*) OVER (PARTITION BY otus.name, taxon_names.cached, taxon_names.type, taxon_names.cached_author_year) AS count')
@otus = Otu.with(dupes: a)
.left_joins(:taxon_name)
.eager_load(:taxon_name)
.joins('JOIN dupes on dupes.id = otus.id')
.select('otus.*, count, dupes.cached, dupes.cached_author_year')
.where('count > 1')
.order('count, name, cached, cached_author_year')
.page(params[:page])
.per(params[:per])
render json: @otus.collect{|o| o.attributes.merge(label: helpers.otu_tag(o), global_id: o.to_global_id.to_s) }
end
|