I'm have this two classes,
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
So once I have a new post like:
Post.new(:title => "Hello World", :body = "Hi there").save
I'm having serious problems to add and remove from the association, like:
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
And how should I remove a post from that association? I'm using the following but definitely its not working:
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
So I really don't know how to delete this from the BoltUser Array.