Skip to content

Instantly share code, notes, and snippets.

@bogn
Last active December 19, 2015 08:49
Show Gist options
  • Select an option

  • Save bogn/5928434 to your computer and use it in GitHub Desktop.

Select an option

Save bogn/5928434 to your computer and use it in GitHub Desktop.

Revisions

  1. bogn revised this gist Jul 4, 2013. 2 changed files with 6 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions group.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    class Group
    include Mongoid::Document

    recursively_embeds_many
    end
    6 changes: 6 additions & 0 deletions move_embedded_to_toplevel.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    class Group
    include Mongoid::Document

    recursively_embeds_many
    end

    # remove from old parent
    @group.parent_group.child_groups.delete @group

  2. bogn revised this gist Jul 4, 2013. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions group.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    class Group
    include Mongoid::Document

    recursively_embeds_many
    end
  3. bogn created this gist Jul 4, 2013.
    11 changes: 11 additions & 0 deletions move_embedded_to_toplevel.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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