Skip to content

Instantly share code, notes, and snippets.

@carlossanchezp
Created July 5, 2013 16:11
Show Gist options
  • Select an option

  • Save carlossanchezp/5935571 to your computer and use it in GitHub Desktop.

Select an option

Save carlossanchezp/5935571 to your computer and use it in GitHub Desktop.
Un ejemplo de uso de UNION para probar
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.id"
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment