我有这两个课,
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 数组中删除它。