私はこの2つのクラスを持っています、
class User
include DataMapper::Resource
property :id, Serial
property :name, String
has n :posts, :through => Resource
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
has n :users, :through => Resource
end
したがって、次のような新しい投稿ができたら:
Post.new(:title => "Hello World", :body = "Hi there").save
次のように、関連付けに追加したり関連付けから削除したりするのに深刻な問題があります。
User.first.posts << Post.first #why do I have to save this as oppose from AR?
(User.first.posts << Post.first).save #this just works if saving the insertion later
また、その関連付けから投稿を削除するにはどうすればよいですか? 私は以下を使用していますが、間違いなく機能していません:
User.first.posts.delete(Post.first) #returns the Post.first, but nothing happens
User.first.posts.delete(Post.first).save #returns true, but nothing happens
User.first.posts.delete(Post.first).destroy #destroy the Post.first, not the association
したがって、BoltUser 配列からこれを削除する方法が本当にわかりません。