I know with normal migrations I could do rename_table but in mongoid I'm not at all sure how to proceed.
I've got all my models/relations/routes/controllers/etc all renamed but I just need to know how to move the data itself.
This is an embedded embeds_one document btw.
UPDATE:
Looks like simply doing:
Model.all.each {|m| m.rename :old_embedded_association_name, :new_embedded_association_name }
Works. Sound sane?
For renaming embedded docs, you treat them just like you would an attribute and rename them using something like this:
ParentModel.all.each {|m| m.rename :old_embedded_association_name, :new_embedded_association_name }
For renaming top level models, you need to access the ruby driver itself and use the #rename_collection method:
Mongoid.database.rename_collection "old_collection_name", "new_collection_name"
To see the old collection name you can do something like this:
Mongoid.database.collections.map {|c| c.name}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With