Skip to content

Instantly share code, notes, and snippets.

@britg
Created January 7, 2012 15:35
Show Gist options
  • Save britg/1575059 to your computer and use it in GitHub Desktop.
Save britg/1575059 to your computer and use it in GitHub Desktop.
class Player < ActiveRecord::Base
# ...
def skills
@skills ||= (Skill.where(:player_id => self.id).first || \
Skill.create(:player_id => self.id))
end
end
class Skill
include Mongoid::Document
field :player_id, :type => Integer
field :accuracy, :type => Integer, :default => 0
field :craftsmanship, :type => Integer, :default => 0
field :perception, :type => Integer, :default => 0
index :player_id, :unique => true
def player
Player.find_by_id(player_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment