Skip to content

Instantly share code, notes, and snippets.

@coffeeaddict
Created August 25, 2010 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coffeeaddict/549399 to your computer and use it in GitHub Desktop.
Save coffeeaddict/549399 to your computer and use it in GitHub Desktop.
class CreateprogramDependencies < ActiveRecord::Migration
def self.up
create_table :program_dependencies do |t|
t.references :dependency, :polymorphic => true
t.references :program
end
end
def self.down
drop_table :program_dependencies
end
end
class Program < ActiveRecord::Base
has_many :program_dependencies
has_many :dependencies, :through => :program_dependencies
has_many :dependent_program_dependencies, :class_name => "ProgramDependency", :as => :dependency
has_many :dependent_programs, :through => :dependent_program_dependencies, :source => :program
end
class ProgramDependency < ActiveRecord::Base
belongs_to :program
belongs_to :dependency, :polymorphic => true
end
class Component < ActiveRecord::Base
has_many :program_dependencies, :as => :dependency
has_many :dependencies, :through => :program_dependencies
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment