
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 1.05 KB | hits: 21 | expires: Never
##
## As a search result, atomic inc works fine on the 'taggings' hash:
##
>> Gif.create!()
=> #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {}, views: 0, upvotes: 0, downvotes: 0>
>> Gif.first.inc('taggings.test', 1)
=> 1
>> Gif.first
=> #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0>
##
## Once a variable, atomic inc creates a new field with a dot inbetween
##
>> variable = Gif.first
=> #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0>
>> variable.inc('taggings.test', 1)
=> 1
>> variable
=> #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0, taggings.test: 1>
>> variable.inc('taggings.test', 1)
=> 2
>> variable
=> #<Gif _id: 4efa9e283b44374c0b000003, _type: nil, tag_ids: [], user_ids: [], taggings: {"test"=>1}, views: 0, upvotes: 0, downvotes: 0, taggings.test: 2>