views:

20

answers:

1

This code is failing on the last line specifically due to the check for table_exists? How do I correctly do this in Datamapper?


require 'sinatra'
require 'DataMapper'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/blog.db")

class Post
    include DataMapper::Resource
    property :id, Serial
    property :title, String
    property :body, Text
    property :created_at, DateTime
end

DataMapper.finalize

# automatically create the post table
DataMapper.auto_migrate! unless Post.table_exists?
A: 

You could use DataMapper.auto_update! which should be non-destructive (adds tables/columns only).

Tass
yeah thank you, that's what I've been doing to work around the issue, however I'd really like to understand what the heck happened to foo.table_exists?
Justin Bozonier