Archive for December, 2008

default ordering with datamapper

Thanks to Adam French for this tip on the datamapper mailinglist.

You’d essentially be update’ing the default query object that all
calls to all() and first() start off with before applying the user’s
parameters

class Post
 include DataMapper::Resource
 #... other properties here
 default_scope(:default).update(:order => [:created_at.desc])
end

datamapper stand alone script (for bugreports)

#!/usr/bin/env ruby

require 'rubygems'

gem 'dm-core', '~>0.9.8'
require 'dm-core'

DataMapper::Logger.new(STDOUT, :debug)
# DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, :debug)

DataMapper.setup(:default, 'sqlite3::memory:')

# here come the demo class(es)

DataMapper.auto_migrate!

# here comes initial creation of records if necessary

puts '-' * 80

# here comes the demo code demonstrating the error or whatever

relevant merb / datamapper ticket information

When filing a ticket for merb or datamapper, it’s a good idea to put the following information into the ticket
(Suggested by Dan Kubb - dkubb in #datamapper)

uname -a (for unixes at least)
ruby --version
mysql --version (or the equivalent for your db)
gem list '\A(?:(?:d[mo]|merb)[_-]|data_?(?:mapper|objects)|extlib)'