class Tema < ApplicationRecord self.table_name = "temas" def self.infos Tema.where(cod_tema_sub: 0).where.not(padrao: "").map { |t| [t.padrao, t.count] }.sort_by { |_, c| -c } end def informativos Informativo.where("tema1 = ? OR tema2 = ? OR tema3 = ?", cod_tema, cod_tema, cod_tema) end end