Created
April 14, 2011 09:15
-
-
Save twiddles/919170 to your computer and use it in GitHub Desktop.
tested on jruby 1.6
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
require 'rubygems' | |
require 'mongoid' | |
class Coach | |
include Mongoid::Document | |
field :name, :type => String | |
belongs_to :coached, :class_name => 'Team', :inverse_of => :coach, :foreign_key => "coach_id" | |
belongs_to :assisted, :class_name => 'Team', :inverse_of => :assist, :foreign_key => "assist_id" | |
end | |
class Team | |
include Mongoid::Document | |
field :name, :type => String | |
has_one :coach, :class_name => 'Coach', :inverse_of => :coached | |
has_one :assist, :class_name => 'Coach', :inverse_of => :assisted | |
end | |
c = Coach.new(:name => "Tom") | |
a = Coach.new(:name => "Dick") | |
t = Team.new(:name => "Allstars") | |
t.coach = c | |
t.assist = a | |
c.coached = t | |
p c | |
p c.coached.assist.assisted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment