An extension to ActiveRecord::Base to support unions
Switch branches/tags
Nothing to show
Latest commit 0e4077f Jun 27, 2009 @tsmango No commit message
Failed to load latest commit information.
lib The options paramter can now be left blank. Feb 28, 2009
README No commit message Jun 26, 2009
init.rb Initial commit. Feb 28, 2009


Plugin Details
This is an extremely naive 'railsification' of a SQL union.

The first parameter, parts, is an array of hashes. Each hash is what you would normally send into a single find and represents each SELECT that will eventually be unioned together.

The second paramter, options, is a hash of remaining options to be applied to the UNION of the parts (ie: order, limit, offset).

A simple (and useless) example would be:
User.union([{:conditions => ['name = ?', 'tom']}, {:conditions => ['name = ?', 'gary']}], {:order => 'created_at'})

This example produces the following SQL:
(SELECT * FROM `users` WHERE (name = 'tom')) UNION (SELECT * FROM `users` WHERE (namae = 'gary')) ORDER BY created_at;

Essentially you can do any union, but it's up to you to make sure you don't pass the wrong stuff in because it's a pretty dumb implementation.

This plugin is available under the MIT license.

Thomas Mango