i'm testing out datamapper with sinatra I read both sinatra book and
datamapper docs and I know that datamapper doesn't support class table
inheritance yet. but I also read that i can use modules for that purpose.
basically i have some common columns like created_at, id etc in all tables
and i don't want to repeat code..
require 'rubygems'
require 'sinatra'
require 'datamapper'
DataMapper::setup(:default, "mysql://blabla")
module Base
def self.included(base)
base.class_eval do
include DataMapper::Resource
property :id, DataMapper::Types::Serial
property :created_at, DateTime
end
end
end
class Post
include Base
property :title, String
property :body, Text
end
DataMapper.finalize
DataMapper.auto_migrate!
DataMapper.auto_upgrade!
get '/' do
@p = Post.create(
:title => 'test'
)
@ps = Post.get(:order => [ :id.desc ], :limit => 20)
@ps.to_
end
I'm getting uninitialized constant DataMapper::Types error from the code
above. If I just type Serial instead, I'm getting uninitialized constant
Serial this time. I searched a lot on google about using modules with
datamapper couldn't find anything useful. Inheritance should be the main
thing if you are using an orm in my point of view so I found it weird... I
don't want to use STI by the way.
I'm using ruby 1.9.1 and dm 1.1
Thanks.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.