Guest User

Untitled

a guest
May 19th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Post
  2. include Mongoid::Document
  3. field :title, :type => String
  4. has_many :comments
  5. end
  6.  
  7. class Comment
  8. include Mongoid::Document
  9. field :body, :type => String
  10. belongs_to :post, :inverse_of => :comments
  11. end
  12.  
  13. @post = Post.create(:title => 'Friday post')
  14. @post.comments.create(:body => 'yay its friday')
  15. @post.comments.create(:body => 'woohoo for tuesday!')
  16.  
  17. # PROBLEM: how do i update the body attribute on that second post I added?
  18. # @post.comments.where(:body => 'woohoo for tuesday!')
  19. # The above query returns a criteria object with the document (Post in this case) that matches, but how do i select and update the proper comment?
Add Comment
Please, Sign In to add comment