First things first: I’m using Ruby 1.9.3 and DataMapper 1.2.0.
I created the following seemingly simple model:
class User
include DataMapper::Resource
property :id, Serial
property :username, String
property :password, BCryptHash
property :name, String
property :email, String
property :created_at, DateTime
end
I can fire this up in an irb shell, it creates a database, and everybody’s happy. But then I try:
tim = User.new(:username => "tim", :password => "password", :name => "Tim", :email => "my@email.com", :created_at => Time.now)
I receive back a User instance, printable to the console and with all its attributes intact. I can run tim.save! and see success. However, if I try to list users at this point, I run up against an error:
irb(main):001:0> User.all
(Object doesn't support #inspect)
=>
irb(main):002:0> User.first
NoMethodError: undefined method `new!' for DateTime:Class
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:153:in `next!'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:153:in `block in read'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:141:in `read'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/repository.rb:162:in `read'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model.rb:377:in `first'
from (irb):5
from /usr/local/Cellar/ruby/1.9.3-p0/bin/irb:12:in `<main>''
Any clues? Nothing else is really turning up on SO or Google for not supporting #inspect, and the Ruby stdlib docs distinctly lack a new! method for DateTime.
Figured this out – it had to do with the version of the
do_sqlite3gem I was using not having been reinstalled since I switched to Ruby 1.9.3. As mentioned in this bug, I needed to reinstall all mydo_*gems to relink against 1.9.3 before it worked.