-
Type:
Bug
-
Resolution: Gone away
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Ruby Drivers
-
None
-
None
-
None
-
None
-
None
-
None
I've run into a weird issue where using insert_one to insert a record works, but then that record can't be updated in Mongo. base_salary in this case is a BigDecimal field. Note how the following base_salary field shows as updates after the set command, but is not being persisted.
attrs = Employee.new(base_salary: "123") Employee.collection.insert_one(**attrs) e = Employee.last puts e.base_salary.to_s => "123.0" puts e.read_attribute_before_type_cast(:base_salary) => "123" e.set(base_salary: "124") puts e.base_salary.to_s => "124.0" puts e.read_attribute_before_type_cast(:base_salary) => "124" e.reload puts e.base_salary.to_s => "123.0" puts e.read_attribute_before_type_cast(:base_salary) => "123" Employee.collection.update_one( { _id: e.id }, { '$set': { base_salary: "124" } }, ) e.reload puts e.base_salary.to_s => "123.0" puts e.read_attribute_before_type_cast(:base_salary) => "123" e = Employee.last puts e.base_salary.to_s => "123.0" puts e.read_attribute_before_type_cast(:base_salary) => "123"
I'm really struggling to figure out why this would be. Anyone got any ideas?