Plugins - has_many_polymorphs

StarAdd to favorites

Makes using ActiveRecord polymorphic associations dead easy. Supports self-references and double-side associations.

class Petfood < ActiveRecord::Base
  has_many_polymorphs :eaters, :from => [:dogs, :cats, :birds]
end

# this is the join table
class EatersPetfood < ActiveRecord::Base
  belongs_to :petfood
  belongs_to :eater, :polymorphic => true
end

# this is an example of one of the child classes
class Dog < ActiveRecord::Base
  # nothing
end

Evan Weaver

http://blog.evanweaver.com/pages/code#polymorphs

svn://rubyforge.org/var/svn/fauna/has_many_polymorphs/trunk

  • Currently 4.3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment
bbnnt 16 Mar 2008

I his plugin would work for an "unlimited-sided=associations" like ?

I'm not understanding exactly the whole concept, might be why I'm asking that; but still, is there a way ?

Brian 14 Feb 2008

To get this plugin working using Rails 2, you need to remove the words 'withoutcallbacks' from base.rb

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?