Module: Export::CSV::TaxonNameOrigin

Defined in:
lib/export/csv/taxon_name_origin.rb

Overview

CSV for for a ResourceRelationship based extension

Constant Summary collapse

HEADERS =

NOT USED

%w{
  id
  name
  original_name
} + Source.column_names.freeze

Class Method Summary collapse

Class Method Details

.csv(scope) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/export/csv/taxon_name_origin.rb', line 12

def self.csv(scope)
  q = ::TaxonName.with(tn_scope: scope.unscope(:select).select(:id))
    .joins('JOIN tn_scope ON tn_scope.id = taxon_names.id')
    .left_joins(:source)
    .select(
     "taxon_names.id as taxon_name_id", 
     "TRIM(CONCAT(taxon_names.cached, ' ', taxon_names.cached_author_year)) as name",
     "TRIM(CONCAT(taxon_names.cached_original_combination, ' ', taxon_names.cached_author_year)) as original_name",
     *Source.column_names.collect{|n| "sources.#{n}"}
    )

  ::Export::CSV.copy_table(q)
end