Skip to content

Instantly share code, notes, and snippets.

@pqwy
Created September 11, 2012 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pqwy/3695935 to your computer and use it in GitHub Desktop.
Save pqwy/3695935 to your computer and use it in GitHub Desktop.
class A
include Mongoid::Document
embeds_one :b
end
class B
include Mongoid::Document
embedded_in :a
end
a = A.new(:b => B.new)
a.save
# At this point, a is persisted, with b embedded.
a.b = a.b
a.b
# => #<B _id: 504eb4cb5f28694e74000007, _type: nil>
# However, b is now deleted from the database.
a.b._id = :foo
# RuntimeError: can't modify frozen Hash
a.reload
a.b
# => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment