私のコードは以下の通りです
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")