我的代码如下
class City
include DataMapper::Resource
has n, :forums
property :id, Serial
property :name, String
property :parent_state, String
property :url, String, :length => 255
end
class Category
include DataMapper::Resource
has n, :forums
property :id, Serial
property :name, String
property :url, String, :length => 255
end
class Forum
include DataMapper::Resource
belongs_to :city
belongs_to :category
has n, :posts
property :id, Serial
property :rss, String, :length => 255
end
class Post
include DataMapper::Resource
belongs_to :forum
property :id, Serial
property :title, String, :length => 255
property :date, Date
property :time, Time
property :body, Text
property :url, String, :length => 255
property :email, String, :length => 255
end
我可以轻松地创建一个新城市......(这是一个循环,我认为你不会真正关心):
City.create(:parent_state => state, :name => citylink.content, :url => citylink.get_attribute('href'))
但对于我的生活,我无法弄清楚我如何创建一个新论坛(所有论坛都是一个 RSS 属性)。我已经尝试用 100 种不同的方式编写它,它要么出错,要么就是不写入数据库,我假设因为没有给出关联,所以它拒绝写入。
我已经阅读了很多 DM 教程和文章,但我仍然不知道我会做什么。
非常感谢任何帮助!
这是我最新的愚蠢样本测试..可能很遥远......
city = City.get(:name => cityname)
Forum.create(:city => city, :rss => "this works now")