Skip to content

Instantly share code, notes, and snippets.

@imajes
Forked from patmaddox/1_user.rb
Created March 10, 2011 00:43
Show Gist options
  • Save imajes/863335 to your computer and use it in GitHub Desktop.
Save imajes/863335 to your computer and use it in GitHub Desktop.
class User
include Mongoid::Document
references_one :best_friend, :class_name => "Person"
references_one :worst_enemy, :class_name => "Person"
end
class Person
include Mongoid::Document
end
person = Person.create!
user = User.create! :best_friend => person
user.best_friend # => #<Person _id: 4d781dbd568ab57112000002, _type: nil, _id: BSON::ObjectId('4d781dbd568ab57112000002')>
user.reload
user.best_friend # => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment