2011-07-18 1 views
0

저는 Sinatra에서 일합니다. 이건 내 모델이야.Datamapper에서 동작하지 마십시오

class Post 
    include DataMapper::Resource 
    property :id, Serial 
    property :title, String 
    property :body, Text 
    property :posted, Boolean, :default => true 

    has n, :comments 
    has n, :tags 
end 

class Comment 
    include DataMapper::Resource 
    property :id, Serial 
    property :user, String 
    property :body, Text 
    property :posted, Boolean, :default => false 

    belongs_to :post 
end 

class Tag 
    include DataMapper::Resource 
    property :id, Serial 
    property :tag, String 
    property :weight, Integer, :default => 1 

    belongs_to :post 
end 

게시물

tags = params[:tags].split(' ') 
post = Post.new(:title=>params[:title],:body=>params[:body]) 
tags.each { |tg| 
    post.tags << Tag.create(:tag=>tg) 
} 
redirect '/admin' if post.save 

하지만 태그를 만듭니다. 수정해야 할 부분은 무엇입니까? 당신은 일대 다 관계를 사용하는 경우

답변

0

, 당신은 post:post 세트 태그를 만들어야합니다

tags.each { |tg| 
    Tag.create(:tag => tg, :post => post) 
}