Created
September 10, 2014 12:02
-
-
Save barsukov/07fbb8fb326a464c9bb5 to your computer and use it in GitHub Desktop.
Move embedded many to has_many mongoid.
This file contains 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
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