updated_at = created_at is not working
I am using mongoid on rails3. I am attempting to perform a very simple migration, but it is not working. When it saves, it keeps saving the original value of a.updated_at, instead of a.created_at. This is very perplexing - anyon开发者_JS百科e has any ideas?
Answer.all.map{|a| a.updated_at = a.created_at; a.save;}
If you still have
Mongoid::Timestamps
included in your model, then, the callback after you save a document will automatically update the updated_at timestamp. I guess that's why you keep seeing your updated_at always at the latest timestamp.
If you want a quick hack, you can remove that line from your model then run your migration.
Do remember to put that line back into your model again after the migration.
精彩评论