Skip to content

Instantly share code, notes, and snippets.

@bogn
Last active December 19, 2015 08:49
Show Gist options
  • Save bogn/5928434 to your computer and use it in GitHub Desktop.
Save bogn/5928434 to your computer and use it in GitHub Desktop.
Mongoid: Moving embedded records (recursively_embeds_many) to top-level. Not actually happy about it, as I don't have the experience with Mongoid to decide whether setting the state like this is risky. But it seems Mongoid 3.1.4 doesn't offer a more elegant way to do this. Feedback very welcome.
class Group
include Mongoid::Document
recursively_embeds_many
end
# remove from old parent
@group.parent_group.child_groups.delete @group
# set new state
@group.destroyed = false
@group.new_record = true
@group._parent = nil
@group.embedded = false
@group.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment