Skip to content

Instantly share code, notes, and snippets.

@barsukov
Created September 10, 2014 12:02
Show Gist options
  • Save barsukov/07fbb8fb326a464c9bb5 to your computer and use it in GitHub Desktop.
Save barsukov/07fbb8fb326a464c9bb5 to your computer and use it in GitHub Desktop.
Move embedded many to has_many mongoid.
child_coll = Mongoid.default_session[:children]
Parent.all.each do |p|
p.childs.all.each do |c|
c.attributes['parent_id'] = p.id
child_coll.insert c.attributes # save children to separate collection
end
p.childs = nil # remove embedded data
p.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment