我正在使用DataMapper的Padrino,并且我正在尝试进行迁移,以便将关联添加到模型中。例如,我从以下内容开始:
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我已经有了创建这三个表的迁移,但没有添加关联。为关联创建迁移的代码是什么?
发布于 2011-01-10 17:08:11
DataMapper.auto_upgrade!将添加新的FK属性
发布于 2011-07-26 03:17:14
auto_upgrade很好,但不允许增量后退。
migration 3, :create_products do
up do
modify_table :post do
add_column :user_id, Integer
end
modify_table :comment do
add_column :post_id, Integer
end
end
down do
modify_table :post do
drop_column :user_id, Integer
end
modify_table :comment do
drop_column :post_id, Integer
end
end
end就这样。
https://stackoverflow.com/questions/4640522
复制相似问题