0

What's the best way to go about migrating Mongoid Slugs to localised versions. Missed adding localise: true on the slug field and now need to migrate my documents to have localised slugs.

eg: currently I have _slugs:["my-slug"], when what I would like is _slugs:{"en":"my-slug"}

Grant Trevor
  • 1,052
  • 9
  • 23

1 Answers1

0

In the end I wrote a rake task to do this which basically amounted to running the below in two separate tasks, running together inside the one block didn't work:

MyModel.all.each do |m|
  m.unset(:_slugs)
end

MyModel.all.each do |m|
  unit.set_slug! 
end

For what it's worth other examples of mongoid migrations can be found here: https://github.com/digitalplaywright/mongoid-slug/wiki/How-to-upgrade-to-1.0.0-or-newer

Grant Trevor
  • 1,052
  • 9
  • 23