-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
In Mongoid 2.1.2, fields whose "type" is Set fail to store their values:
MongoidSandbox dev > class Foo MongoidSandbox dev .. include Mongoid::Document MongoidSandbox dev .. field :s, :type => Set MongoidSandbox dev .. end => #<Mongoid::Fields::Serializable::Set:0xa06935c @options={:type=>Mongoid::Persistence::Atomic::Set}, name"s", default_valuenil, labelnil, cast_on_readtrue MongoidSandbox dev > MongoidSandbox dev > foo = Foo.new => #<Foo _id: 4e36cd692b58af7f61000002, _type: nil, s: []> MongoidSandbox dev > MongoidSandbox dev > foo.s.add 123 => #<Set: {123}> MongoidSandbox dev > foo.s => #<Set: {}> MongoidSandbox dev > foo.s.add 456 => #<Set: {456}> MongoidSandbox dev > foo.s => #<Set: {}> MongoidSandbox dev > foo.save => true MongoidSandbox dev > foo.reload => #<Foo _id: 4e36cd692b58af7f61000002, _type: nil, s: []> MongoidSandbox dev > MongoidSandbox dev > foo.s => #<Set: {}>
I'm pretty sure that a new Set object is being created every time the document's Set-field is accessed:
MongoidSandbox dev > f = Foo.new
=> #<Foo _id: 4e36cdf72b58af7f61000003, _type: nil, s: []>
MongoidSandbox dev >
MongoidSandbox dev >
MongoidSandbox dev > f.s.object_id
=> 83667340
MongoidSandbox dev > f.s.object_id
=> 83633830
MongoidSandbox dev > f.s.object_id
=> 83596510