Created
August 27, 2010 14:47
-
-
Save workmad3/553494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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