milesrichardson / ParsePy

A relatively up-to-date fork of ParsePy, the Python wrapper for the Parse.com API. Originally maintained by @dgrtwo
MIT License
516 stars 184 forks source link

addUnique #119

Closed flound1129 closed 9 years ago

flound1129 commented 9 years ago

implements addUnique for array columns

flound1129 commented 9 years ago

Looks like someone already committed a better version of this. Closing.

somq commented 6 years ago

Hi @flound1129 @milesrichardson, I'd lilke to know why that PR and #117 were closed ? Can you enlight me on what is the right way of doing add, addUnique and remove please ?

milesrichardson commented 6 years ago

Hey @somq

I inherited this project from the original dev, and at the time of inheriting I closed stale issues.

This issue looks like it was closed because there was already code for it, but I don't see that code in the repo now...

I'll look into this. Hold tight

milesrichardson commented 6 years ago

@somq I just manually merged #117

If you install from master on pip (as specified in the readme), you can now use the following methods:

def addToArray(self, key, objects):
    payload = {
        key: {
            '__op': 'Add', 'objects': objects
            }
        }
    self.__class__.PUT(self._absolute_url, **payload)
    self.__dict__[key] = self.__dict__.get(key, []) + objects

def addUniqueToArray(self, key, objects):
    payload = {
        key: {
            '__op': 'AddUnique', 'objects': objects
            }
        }
    self.__class__.PUT(self._absolute_url, **payload)
    data = self.__dict__.get(key, [])
    self.__dict__[key] = data + [x for x in objects if x not in data]

def removeFromArray(self, key, objects):
    payload = {
        key: {
            '__op': 'Remove', 'objects': objects
            }
        }
    self.__class__.PUT(self._absolute_url, **payload)
    self.__dict__[key] = [x for x in self.__dict__.get(key, []) if x not in objects]
somq commented 6 years ago

@milesrichardson Alright, thanks a lot for your fast answer. We will pull and try the latest merge and let you know asap if all 3 methods are working as expected.