Last active
December 19, 2015 08:49
-
-
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.
This file contains hidden or 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
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