theycallmeswift/hackerleague.org — Issue #4: As the system, I support polymorphic applications
Author: theycallmeswift
Created: 2011-10-25 19:29:03+00:00
State: open

In oder to handle applications (joining organizations, teams, hackathons, etc..) the system should have a basic application model that is subclassed into specific types of applications and polymorphically embedded in models that have application processes

class Organization
include Mongoid::Document
has_many :applications, as: :applicable
end

class Hackathon
include Mongoid::Document
has_many :applications, as: :applicable
end

class Application
include Mongoid::Document
belongs_to :applicable, polymorphic: true
end

More info on polymorphism:

When a child referenced document can belong to more than one type of parent document, you can tell Mongoid to support this by adding the as option to the definition on the parents, and the polymorphic option on the child.

Source: http://mongoid.org/docs/relations/referenced/1-n.html