scope_tool.rb 250 Bytes Edit Raw Blame History 1 2 3 4 5 6 7 8 9 10 11 12 13 module ScopeTool def union(*scopes) model = scopes.first.class_name.constantize scopes = scopes.map &:to_sql model.from "(\n#{scopes.join("\nUNION\n")}\n) as #{model.table_name}" end class << self include ScopeTool end end