Skip to content

Instantly share code, notes, and snippets.

@bill-transue
Forked from workmad3/component.rb
Created August 27, 2010 14:54
Show Gist options
  • Save bill-transue/553510 to your computer and use it in GitHub Desktop.
Save bill-transue/553510 to your computer and use it in GitHub Desktop.
class Component < ActiveRecord::Base
has_many :sub_components
#this is the 'other side' of the has_many :components statement
belongs_to :component
has_one :component
end
class CreateComponent < ActiveRecord::Migration
def self.up
create_table :components do |t|
#need this here to allow components to reference each other
t.references :component
t.integer :elevation_index
t.string :oreintation
t.timestamps
end
def self.down
drop_table :components
end
end
class CreateSubComponent < ActiveRecord::Migration
def self.up
create_table :sub_components do |t|
t.references :component
t.string :sub_component
t.timestamps
end
def self.down
drop_table :sub_components
end
end
#Inherits from AR::Base rather than Component because we don't really want STI here (which is what you get if you inherit from a model)
class SubComponent < ActiveRecord::Base
belongs_to :component
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment