I have an existing Rails 3 application using ActiveRecord, and I want to switch to Datamapper. The instructions given in the dm-rails page only talk about creating a new application. Does anyone know how to throw away all activerecord dependancies and migrate to datamapper?
Thanks!
It’s realtively straightforward, but there are a couple of things you need to do.
In your Gemfile, remove “rails” and instead require the following.
Where
RAILS_VERSIONis the version of Rails you want to use (e.g.~> 3.1). This is basically all of rails except ActiveRecord.At the top of config/application.rb, remove the require for rails (I forget what the original require looks like) and replace it with specific requires for the railties you need.
I think the only other one is a Test::Unit railtie, but we’re not using Test::Unit, so we don’t include it.
Finally, if you want to use the identity map (I suggest you do, but it’s not needed), place in your ApplicationController’s class body:
That should be everything; the rest is just configuring your database.yml according to the README (it’s pretty much cross-compatible with a standard rails one anyway).
For reference, take a look at what the generators does:
If you look at the contents of those two files you’ll see the extra stuff you’d get if you had used the generator.