module GroupedLatest

Constants

VERSION

Public Class Methods

gl_arel_exists(grouped) click to toggle source
# File lib/grouped_latest.rb, line 19
def gl_arel_exists(grouped)
  table = arel_table
  sub = arel_table.alias('sub')
  select = table.where(table[grouped].eq(sub[grouped]))
             .where(table[latest_column].lt(sub[latest_column]))
             .project('1').from(sub)
  where(select.exists.not)
end
gl_arel_in(grouped) click to toggle source
# File lib/grouped_latest.rb, line 13
def gl_arel_in(grouped)
  table = arel_table
  max = table.project(table[latest_column].maximum).group(grouped)
  where(table[latest_column].in(max))
end
gl_array_in(grouped) click to toggle source
# File lib/grouped_latest.rb, line 28
def gl_array_in(grouped)
  max = group(grouped).maximum(latest_column).values
  where(latest_column => max)
end