Created
December 28, 2011 04:46
-
-
Save bcjordan/1526356 to your computer and use it in GitHub Desktop.
Mongoid Hash atomic increment issue
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
## | |
## 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment