Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created January 17, 2013 13:15
Show Gist options
  • Save betawaffle/4555872 to your computer and use it in GitHub Desktop.
Save betawaffle/4555872 to your computer and use it in GitHub Desktop.
module WithArchive
def with_archive
columns = column_names
archive_class = const_get(:Archive)
archive_columns = columns.map { |c| c == 'state' ? "'disabled' AS state" : c }
from <<-sql
(#{unscoped.select(columns.join(', ')).to_sql}
UNION
#{archive_class.unscoped.select(archive_columns.join(', ')).to_sql}
) as #{table_name}
sql
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment