Acts As Union plugin

Plugin details

acts_as_union simply presents a union’ed view of one or more ActiveRecord relationships (has_many or has_and_belongs_to_many, acts_as_network, etc).

Websitehttp://github.com/mdi/acts_as_union Repositorygit://github.com/mdi/acts_as_union.git Author Michael Irwin Tags acts, union LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install git://github.com/mdi/acts_as_union.git
class Person < ActiveRecord::Base
  acts_as_network :friends
  acts_as_network :colleagues, :through => :invites, :foreign_key => 'person_id', 
                  :conditions => ["is_accepted = 't'"]
  acts_as_union   :aquantainces, [:friends, :colleagues]
end


In this case a call to the aquantainces method will return a UnionCollection on both a person’s friends and their colleagues. Likewise, finder operations will work accross the two distinct sets as if they were one.

Thus, for the following code

stephen = Person.find_by_name('Stephen')
billy   = stephen.aquantainces.find_by_name('Billy')


both Stephen’s friends and colleagues collections would be searched for someone named Billy.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 5 months ago