app/models/list.rb
#For lists, returns first_observation (array of [date, observation_id])
#where date represents the first date observed (e.g. not first date added to iNat)
For lists, returns first_observation (array of [date, observation_id])
where date represents the first date observed
For lists returns first_observation ( array of [ date observation_id ] ) where date represents the first date observed
def cache_columns_query_for(lt)
    lt = ListedTaxon.find_by_id(lt) unless lt.is_a?(ListedTaxon)
    return nil unless lt
    ancestry_clause = [lt.taxon_ancestor_ids, lt.taxon_id].flatten.map{|i| i.blank? ? nil : i}.compact.join('/')
    sql_key = "EXTRACT(month FROM observed_on) || substr(quality_grade,1,1)"
    <<-SQL
      SELECT
        min(COALESCE(time_observed_at::varchar, observed_on::varchar, '0') || ',' || o.id::varchar) AS first_observation,
        max(COALESCE(time_observed_at::varchar, observed_on::varchar, '0') || ',' || o.id::varchar) AS last_observation,
        count(*),
        (#{sql_key}) AS key
      FROM
        observations o
          LEFT OUTER JOIN taxa t ON t.id = o.taxon_id
      WHERE
        o.user_id = #{user_id} AND
        (
          o.taxon_id = #{lt.taxon_id} OR 
          t.ancestry = '#{ancestry_clause}' OR
          t.ancestry LIKE '#{ancestry_clause}/%'
        )
      GROUP BY #{sql_key}
    SQL
  end
def cache_columns_query_for ( lt ) lt = ListedTaxon . find_by_id ( lt ) unless lt . is_a? ( ListedTaxon ) return nil unless lt ancestry_clause = [ lt . taxon_ancestor_ids , lt . taxon_id ] . flatten . map { | i | i . blank? ? nil : i } . compact . join ( '/' ) sql_key = "EXTRACT(month FROM observed_on) || substr(quality_grade,1,1)" <<-SQL 
      SELECT
        min(COALESCE(time_observed_at::varchar, observed_on::varchar, '0') || ',' || o.id::varchar) AS first_observation,
        max(COALESCE(time_observed_at::varchar, observed_on::varchar, '0') || ',' || o.id::varchar) AS last_observation,
        count(*),
        ( #{ sql_key } ) AS key
      FROM
        observations o
          LEFT OUTER JOIN taxa t ON t.id = o.taxon_id
      WHERE
        o.user_id =  #{ user_id }  AND
        (
          o.taxon_id =  #{ lt . taxon_id }  OR 
          t.ancestry = ' #{ ancestry_clause } ' OR
          t.ancestry LIKE ' #{ ancestry_clause } /%'
        )
      GROUP BY  #{ sql_key } SQL end
For lists, returns first_observation (array of [date, observation_id])
where date represents the first date observed (e.g.
For lists returns first_observation ( array of [ date observation_id ] ) where date represents the first date observed ( e . g .
lt