migrating to datamapper 0.10.0

Some prerequisites to get ready for datamapper 0.10.0

You need to have at least rubygems 1.3.5
You need to have a reasonably fresh rspec

The following git instructions only apply if you want to keep track of the ongoing datamapper development.
You can safely omit them if you followed the instructions in the original post to the google group.

sudo gem install addressable
mkdir git-sources
cd git-sources/
git clone git://github.com/datamapper/extlib.git
git clone git://github.com/datamapper/do.git
git clone git://github.com/datamapper/dm-core.git
git clone git://github.com/datamapper/dm-more.git
git clone git://github.com/snusnu/merb.git
cd extlib/
rake install
cd ..
cd do/data_objects/
rake install
cd ../do_sqlite3/
rake install
cd ../do_xxx/
rake install
cd ../..
cd dm-core/
rake install
cd ..
cd dm-more/
rake install
cd ..

Migrating your app to datamapper 0.10.0 is pretty painless,
you mainly need to deal with deprecation notices:

options[:class_name] is now options[:model]
PropertySet#has_property? is now PropertySet#named?
update_attributes is now update and doesn’t support the *allow_attributes parameter anymore
new_record? is now new?
:mutable => true on a has(n, :things, :through => :others) relationship is not supported/necessary anymore
:remote_name option for has(n, :things, :through => :others) is now called :via
:some_property.in => ['val1', 'val2'] is not supported anymore in queries, just use :some_property => ['val1', 'val2']
belongs_to :parent now defaults to :nullable => false
When adding to associations, post.comments.build(...) is now post.comments.new(...)

If you’re using merb and you’re fine using the master branch (upcoming merb-1.1) and not the latest release, all you need to do is update your wycats/merb clone or run the following commands.

cd git-sources/
git clone git://github.com/wycats/merb.git
cd merb
sudo rake install

If you however want to use datamapper 0.10.0 with latest merb release (1.0.12 at the time of writing) you will currently need to run these commands (Thx again teamon for taking the time to backport stuff!).
merb-1.0.13 will be released soon and will be fully compatible with datamapper 0.10.0.

cd git-sources/
git clone git://github.com/wycats/merb.git
cd merb
git checkout -b 1.0.x --track origin/1.0.x
sudo rake install

You will maybe get some warnings about merb-more but you can safely ignore them.



17 Responses (Add Your Comment)

  1. thanks for the instructions

    check line 12 on the first pastie. you need an prepending “../” on the dm-core

  2. Thx! updated the post .. sorry for the awful formatting :)

  3. Thank you. Will be good if you add instructions to update merb gems also. Like which branch use and which gems compile.

  4. Dmitry

    Sorry for replying late. I added instructions how to install my fork of merb and two missing dm changes.

  5. Hey snusnu,

    Thanks for the awesome walkthrough in preperation of 0.10.

    Just letting you know lines 3&4 of the second source code block should be swapped.

    Thanks again

  6. Thx dude, good catch! Updated the post.

  7. appreciate this, thx

  8. Glad you found it useful! btw, I updated the post to remove the :child_key to :target_key transition. in fact, that’s not implemented yet, but will be in the future.

  9. Thanks for the guide. If I want to revert back to the older (current) version what commands to I need?
    I tried reinstalling dm etc but merb says “can’t activate merb-core (= 1.0.12, runtime), already activated merb-core-1.1″
    I’m new to rake etc. Did the rake installs tell my system to use 1.1 files? How do I undo this change?
    Cheers,
    George

  10. George,

    For a command to uninstall all datamapper related gems, have a look at http://alfred.datamapper.org/posts/55

    If you need to revert your merb installation to 1.0.12, you can probably come up with a snippet similar to the one for datamapper that I linked above. If you don’t do that, it’s probably easy enough to just do sudo gem uninstall merb and the same for all other related merb gems. The uninstall command will ask you which version to remove. It should be straight forward (albeit a little tedious maybe) to remove all merb-1.1 related gems.

    Out of interest, why do you feel the need to revert?

  11. Hey guys,

    wycats pulled the datamapper 0.10.0 support into the officail merb repo master branch.

    If you’re fine using master, you can safely switch your remotes back to wycats/merb. If you’re using the backport branch for merb 1.0.12, keep on doing so and you should be fine.

    I updated the post accordingly

  12. One thing that bit me that wasn’t mentioned is that belongs_to associations now default to :nullable => false instead of true.

  13. Hey swim,

    Somehow forgot to mention that. I updated the post.

    Thx

  14. When adding to associations, #build is now #new

    @comment = @post.comments.build(…)

    @comment = @post.comments.new(…)

  15. Thx Roy, I updated the post.

  16. Also, options[:serial]=true has been deprecated in favor of using the Serial type.

    The bigger change is to the adapter interface, which doesn’t matter to as many people directly, but could be a problem if you are using some less frequently maintained adapters.

    read_one & read_many -> read
    with different semantics–read must return an array of either Hashes or Resources.

    read_one returned a Resource and read_many returned a Collection.

    @uri -> @options which makes more sense

    The new interface is much cleaner and easier to write against.

  17. I hit a wall with this error:

    NoMethodError: undefined method `name' for nil:NilClass

    Later I discovered through poking at it with irb and googling around, that :child_key is now :target_key and this is what caused the problem. The error is non-obvious.

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>