DataMapper 关联迁移
我将 Padrino 与 DataMapper 结合使用,并且尝试进行迁移以将关联添加到模型。例如,我以此开始:
class User
include DataMapper::Resource
property :id, Serial
property :name, String
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
end
class Comment
include DataMapper::Resource
property :id, Serial
property :name, String
end
我以以下内容结束:
class User
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :posts
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
belongs_to :user
has n, :comment
end
class Comment
include DataMapper::Resource
property :id, Serial
property :name, String
belongs_to :post
end
我已经进行了用于创建三个表的迁移,但我没有用于添加关联。为关联创建迁移的代码是什么?
I'm using Padrino with DataMapper, and I'm trying to make a migration for adding an association to a model. For example, I begin with this:
class User
include DataMapper::Resource
property :id, Serial
property :name, String
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
end
class Comment
include DataMapper::Resource
property :id, Serial
property :name, String
end
And I end with the following:
class User
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :posts
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
belongs_to :user
has n, :comment
end
class Comment
include DataMapper::Resource
property :id, Serial
property :name, String
belongs_to :post
end
I already have the migration for creating the three tables, but I do not for adding the associations. What would the code be for creating the migration for the associations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DataMapper.auto_upgrade!将添加新的 FK 属性
DataMapper.auto_upgrade! will add new FK properties
auto_upgrade 很好,但不允许增量后退。
就是这样。
auto_upgrade is nice, but won't allow incremental step back.
that's it.