Rename the model with a mangoid

I know that with normal migrations I could do rename_table, but in mongoid I'm not at all sure how to proceed.

I have all my models / relationships / routes / controllers / etc, which are all renamed, but I just need to know how to transfer the data.

This is the embeds_one btw embedded document.

UPDATE:

It seems simple:

Model.all.each {|m| m.rename :old_embedded_association_name, :new_embedded_association_name }

Works. Sounds great?

+5
source share
3 answers

To rename inline documents, you treat them the same as an attribute, and rename them using something like this:

ParentModel.all.each {|m| m.rename :old_embedded_association_name, :new_embedded_association_name }

To rename 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"

, - :

Mongoid.database.collections.map {|c| c.name}

+1

. (https://github.com/mongoid/moped/blob/master/lib/moped/collection.rb#L55).

Mongoid.default_session[:old_name].rename(:new_name)

.

OldModel.collection.name

+1

Based on what you said and the documentation, it seems you should do it this way

Model.rename(:old_name, :new_name)
0
source

All Articles