Commit 5a86ba0c by Miles Richardson

Fix issue #153

parent b2bf2e27
......@@ -126,7 +126,7 @@ class EmbeddedObject(ParseType):
return klass(**kw)
@complex_type()
@complex_type('Relation')
class Relation(ParseType):
@classmethod
def from_native(cls, **kw):
......@@ -178,10 +178,9 @@ class Relation(ParseType):
return repr
def _to_native(self):
return {
'__type': 'Relation',
'className': self.relatedClassName
}
# Saving relations is a separate operation and thus should never need
# to convert this field _to_native
return None
def add(self, objs):
"""Adds a Parse.Object or an array of Parse.Objects to the relation."""
......
......@@ -118,7 +118,7 @@ class User(ParseResource):
def __repr__(self):
return '<User:%s (Id %s)>' % (getattr(self, 'username', None), self.objectId)
def removeRelation(self, key, className, objectsId):
self.manageRelation('RemoveRelation', key, className, objectsId)
......@@ -139,7 +139,19 @@ class User(ParseResource):
}
}
self.__class__.PUT(self._absolute_url, **payload)
self.__dict__[key] = ''
# Commented this line out to fix the saving relation issue --
# it's better to just return None in Relation._to_native
# self.__dict__[key] = ''
def relation(self, key):
if not hasattr(self, key):
return Relation(parentObject=self, key=key)
try:
return getattr(self, key).with_parent(parentObject=self, key=key)
except:
raise ParseError("Column '%s' is not a Relation." % (key,))
User.Query = QueryManager(User)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment