Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ##
  2. ## As a search result, atomic inc works fine on the 'taggings' hash:
  3. ##
  4. >> Gif.create!()
  5. => #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {}, views: 0, upvotes: 0, downvotes: 0>
  6. >> Gif.first.inc('taggings.test', 1)
  7. => 1
  8. >> Gif.first
  9. => #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0>
  10.  
  11. ##
  12. ## Once a variable, atomic inc creates a new field with a dot inbetween
  13. ##
  14. >> variable = Gif.first
  15. => #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0>
  16. >> variable.inc('taggings.test', 1)
  17. => 1
  18. >> variable
  19. => #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0, taggings.test: 1>
  20. >> variable.inc('taggings.test', 1)
  21. => 2
  22. >> variable
  23. => #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0, taggings.test: 2>