lib/volt/models/persistors/model_store.rb
# Do the actual writing of data to the database, only runs on the backend.
Do the actual writing of data to the database, only runs on the backend.
Do the actual writing of data to the database only runs on the backend .
def save_to_db!(values)
          errors = @model.errors
          return errors if errors.present?
          id = values[:_id]
          begin
            db[collection].insert(values)
          rescue Mongo::OperationFailure => error
            if error.message[/^11000[:]/]
              update_values = values.dup
              update_values.delete(:_id)
              db[collection].update({ _id: id }, update_values)
            else
              return { error: error.message }
            end
          end
          QueryTasks.live_query_pool.updated_collection(collection.to_s, Thread.current['in_channel'])
          return {}
        end
def save_to_db! ( values ) errors = @model . errors return errors if errors . present? id = values [ :_id ] begin db [ collection ] . insert ( values ) rescue Mongo :: OperationFailure => error if error . message [ / ^11000[:] / ] update_values = values . dup update_values . delete ( :_id ) db [ collection ] . update ( { _id : id } , update_values ) else return { error : error . message } end end QueryTasks . live_query_pool . updated_collection ( collection . to_s , Thread . current [ 'in_channel' ] ) return { } end
Do the actual writing of data to the database, only runs on the backend.
Do the actual writing of data to the database only runs on the backend .
# Check to make sure the model has no validation errors. # Passed, save it # Try to create # TODO: Seems mongo is dumb and doesn't let you upsert with custom id's # values['_id'] = BSON::ObjectId('_id') if values['_id'] # Really mongo client? # Update because the id already exists # puts "Update Collection: #{collection.inspect} - #{values.inspect} -- #{Thread.current['in_channel'].inspect}"
values