thiagolocatelli / parse4j

Java Library to deal with Parse (parse.com) REST API
http://thiagolocatelli.github.io/parse4j
143 stars 117 forks source link

Delete object from Parse #25

Open ucarseyhan opened 9 years ago

ucarseyhan commented 9 years ago

Hi,

I have a question related with the delete operation. Do I need to specify the objectId for delete operation?

Regards.

raytrask commented 9 years ago

Yes. But I'm guessing by you question you want to delete by something else other than the objectId. Heres the code I used (in groovy).

static def deleteCloudObjects(String className, Map keyMap){

        assert  className != null && keyMap && keyMap.size() != 0  , "bad args in deleteCloudObjects"

        if (!ServerUtils.saveToCloud){
            return
        }

        ParseQuery pq = new ParseQuery(className)

        List<ParseObject> list = null

        keyMap.each { entry ->
            pq.whereEqualTo(entry.key, entry.value)
        }
        list = pq.find()   // TODO Error checking???

        list.each { 
            println "Deleting " + it
            it.delete();    
        }
    }