def METHOD_NAME(id, v):
    chat_message = g.db.query(ChatMessage).filter(ChatMessage.id == id).one_or_none()
    if chat_message:
        # Zero out all the quote_id references to this message
        messages_quoting_this = g.db.query(ChatMessage).filter(ChatMessage.quote_id == id).all()
        for message in messages_quoting_this:
            message.quote_id = None 
        # Now, delete the chat_message
        g.db.METHOD_NAME(chat_message)
        g.db.commit()
        emit('delete', id, broadcast=True)