mongoid/mongoid — Issue #1425: Cannot clone/dup a Mongoid document that has embedded document(s)
Author: aagrawal2001
Created: 2011-11-11 23:54:55+00:00
State: open

Simple way to reproduce this is:

artist.freeze.dup

Where artist is an instance of the Artist object from the front page of the Mongoid documentation (i.e. it contains embedded instruments and the instruments array is non-empty).

The reason here is that initialize_copy calls as_document which actually modifies the document being cloned/as_document-ed when embedded fields are present.

One solution would be to perform as_document in the freeze operation. I'll submit a pull request.