0.0
No commit activity in last 3 years
No release in over 3 years
A lightweight gem that provides two AR:Relation methods to create unions and sets #& and #|
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

easily create unions and intersections in ActiveRecord.

Setup

gem 'easy_union_set'

Easy to use, So I'll jump straight into the examples

to create a UNION

Project.where("title LIKE '%a%'") | Project.having("LENGTH(description) > 10").group(:id)

# => SELECT "projects".* FROM ( SELECT "projects".* FROM "projects"  WHERE (title LIKE '%a%') UNION SELECT "projects".* FROM "projects"  GROUP BY id HAVING LENGTH(description) > 10 ) "projects"

to create an INTERSECT

Project.where("title LIKE '%a%'") & Project.having("LENGTH(description) > 10").group(:id)

# => SELECT "projects".* FROM ( SELECT "projects".* FROM "projects"  WHERE (title LIKE '%a%') INTERSECT SELECT "projects".* FROM "projects"  GROUP BY id HAVING LENGTH(description) > 10 ) "projects"

to create a UNION ALL

Project.where("title LIKE '%a%'") | {:all => Project.having("LENGTH(description) > 10").group(:id)}

# => SELECT "projects".* FROM ( SELECT "projects".* FROM "projects"  WHERE (title LIKE '%a%') UNION ALL SELECT "projects".* FROM "projects"  GROUP BY id HAVING LENGTH(description) > 10 ) "projects"

if for some reason you'd still rather make multiple queries and make a ruby union simply call #to_a on the AR:Relation object before using the #& or #| methods.