-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I'm using mongoid 3.0.14, replica set, safe:true and consistency:eventual.
My model has a boolean field with a validates_uniqueness_of :active, :if => :active
(only one record should be :active = true)
My controller does something like this..
model = Model.with(consistency: :strong).find(params[:id])
Model.update_all(:active => false)
model.active = true
model.save
sometimes 'save' operation returns an error "active field already in use".
that seems strange for me. I dont understand how validation works, but the only thing I could imagine is that mongoid is validating on secondary during save operation.
when I force the save code to primary "model.with(consistency: :strong).save" that error does not occur anymore.
if I'm correct this must be a bug. Validations on save should be on primary node (replicas + validation).