Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addUnique #119

Closed
wants to merge 1 commit into from
Closed

addUnique #119

wants to merge 1 commit into from

Conversation

flound1129
Copy link

implements addUnique for array columns

@flound1129
Copy link
Author

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

@flound1129 flound1129 closed this Jul 31, 2015
@somq
Copy link

somq commented Mar 7, 2018

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
Copy link
Owner

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
Copy link
Owner

@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
Copy link

somq commented Mar 7, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants