On 18/05/11 7:00 AM, Koray Taylan Davgana wrote:
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.
Have you tried:
DataMapper::Property::Serial or
::DataMapper::Property::Serial or
::DataMapper::Types::Serial
We use the same method for you for class table inheritance and it works
well. From the example, you are just looking to DRY up models, not
inheritance --- to map an inheritance chain, you need a base table with
FKs pointing into it. (This isn't a bad thing, just a thing.)
Cheers,
Xavier
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.
--
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.