Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created August 27, 2010 14:47
Show Gist options
  • Save workmad3/553494 to your computer and use it in GitHub Desktop.
Save workmad3/553494 to your computer and use it in GitHub Desktop.
class Component < ActiveRecord::Base
has_many :components
#this is the 'other side' of the has_many :components statement
belongs_to :component
has_one :sub_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.references :sub_component #don't need this because sub_components aren't referencing each other
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