`
tim.teng
  • 浏览: 9811 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

create table with ActiveRecord alone

阅读更多

You could use migrations. But thats just another way of describing the table.

If you want another approach (defining a model and then letting the abstraction
layer create the required database), you could use datamapper instead[1].

Then, you class will look like this:

 1 class Post
 2   include DataMapper::Resource
 3   property :id,         Integer,  :serial => true
 4   property :title,      String
 5   property :subtitle,   String  :lazy => [:show]
 6   property :body,       Text      :lazy => [:show]
 7   property :views,      Integer, :lazy => [:show]
 8   property :summary,    Text
 9 end

#and

Post.auto_migrate!

will create/migrate your table automatically.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics