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.
create table with ActiveRecord alone
最新推荐文章于 2017-02-01 20:16:00 发布
本文介绍了一种通过定义模型并利用抽象层自动创建所需数据库的方法。使用DataMapper库可以轻松实现这一目标,只需几行代码即可完成表的定义与自动迁移。
205

被折叠的 条评论
为什么被折叠?



