Skip to content

@jnunemaker /atomic_embedded_pull.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Atomically remove embedded doc from doc in mongomapper
require 'pp'
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = 'testing'
class Comment
include MongoMapper::EmbeddedDocument
end
class Post
include MongoMapper::Document
many :comments do
def destroy(id)
proxy_owner.pull(:comments => {:_id => id})
end
end
end
Post.delete_all
comment = Comment.new(:name => 'Peter')
post = Post.create(:title => "Foo", :comments => [comment, Comment.new(:name => 'John')])
pp Post.collection.find.to_a
post.comments.destroy(comment.id)
pp Post.collection.find.to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.