Method: Auth::Shopping::BarCode.clear_object
- Defined in:
- app/models/auth/shopping/bar_code.rb
.clear_object(assigned_to_object_id) ⇒ Object
tries to clear the assigned object id from the barcode record. if it returns null, then it will first check if any record exists, to which that object_id was assigned, if no record exists, returns true(because it means that this object id was already cleared from some barcode before.), on the other hand if some record is found, then returns false.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/auth/shopping/bar_code.rb', line 39 def self.clear_object(assigned_to_object_id) ## we just do a find one and update begin returned_document = where(:assigned_to_object_id => assigned_to_object_id).find_one_and_update( { "$set" => { "assigned_to_object_id" => nil, "assigned_to_object_class" => nil } }, { :return_document => :after } ) true rescue doc_exists = where(:assigned_to_object_id => assigned_to_object_id).first return true unless doc_exists return false end end |