Created
February 5, 2010 02:23
-
-
Save durran/295419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post | |
include Mongoid::Document | |
field :title, :type => String | |
has_many :comments do | |
def update(selector, value) | |
@target.each { |c| c.body = value if c.matches?(selector) } | |
end | |
end | |
end | |
class Comment | |
include Mongoid::Document | |
field :body, :type => String | |
belongs_to :post, :inverse_of => :comments | |
end | |
@post = Post.create(:title => 'Friday post') | |
@post.comments.create(:body => 'yay its friday') | |
@post.comments.create(:body => 'woohoo for tuesday!') | |
comments = @post.comments.where(:body => 'woohoo for tuesday') | |
comments.each { |comment| comment.body = "New Value" } | |
comments.first.body = "New Value" | |
@post.comments.update(:body => "woohoo for tuesday", "woot for wed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment