As the time has come to it, I’m upgrading Tathkarti now to Ruby on Rails 4, and with that many changes and incompatibility arises ofcourse. As it happens I’m using MongoDB and Mongoid for the database backend mostly, and since Mongoid 4 gem hasn’t officially been released yet, partly because they were waiting on 10gen’s Ruby 2.0 MongoDB driver, which seems to now be delayed until March, 14. What that means is you’re left with either waiting, which doesn’t seem possible for me as gems incompatibility are beginning to bother me, or use the Mongoid 4 Alpha, which is what I’m doing. For that just change the Gemfile accordingly:
gem “mongoid”, github: ‘mongoid/mongoid’
And run bundle install. Now it’s working so far in development better than I expected, but I faced some weird behaviour when trying to delete all delete_all or destroy all destroy_all embedded documents, this is what happens:
m=Model.first m.children.count => 3 m.children.destroy_all m.save # just to be extra sure m.children.count => 0 m.reload m.children.count => 3
Why did this happen? I only found old reported problems that didn’t seem related. After some trial and errors, I found out you now have to do it like this:
m=Model.first m.children.count => 3 m.children.all.destroy_all m.children.count => 0 m.reload m.children.count => 0
Why is that? I assume it is related to the lazy database loading, but I’m not sure why it behaves this way. If anyone has a better idea, do share them in the comments.