Created
January 29, 2011 02:51
-
-
Save Osmose/801456 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 for a table called "zombies" in MySQL with some columns | |
class Zombie < ActiveRecord::Base | |
validates_presence_of :name #name column must exist before saving to DB | |
validates_uniqueness_of :name #names must be unique | |
has_many :weapons #The weapons table will have a column describing ownership by zombies | |
end | |
# Class for "weapons" table | |
class Weapon < ActiveRecord::Base | |
belongs_to :zombie #Other half of ownership, column will be called "zombie_id" | |
end | |
# Get a list of all weapons that the zombie with id 3 owns | |
w = Zombie.find(3).weapons |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment