Commit 05c4ffd8 by Felipe Lavratti

Added automatic conversion of array of pointers to parse object.

parent 15faf6bd
...@@ -35,6 +35,8 @@ class ParseType(object): ...@@ -35,6 +35,8 @@ class ParseType(object):
@staticmethod @staticmethod
def convert_from_parse(parse_key, parse_data): def convert_from_parse(parse_key, parse_data):
if isinstance(parse_data, list):
return [ParseType.convert_from_parse(parse_key, item) for item in parse_data]
parse_type = None parse_type = None
if isinstance(parse_data, dict): if isinstance(parse_data, dict):
...@@ -455,7 +457,7 @@ class Object(six.with_metaclass(ObjectMetaclass, ParseResource)): ...@@ -455,7 +457,7 @@ class Object(six.with_metaclass(ObjectMetaclass, ParseResource)):
} }
self.__class__.PUT(self._absolute_url, **payload) self.__class__.PUT(self._absolute_url, **payload)
self.__dict__[key] += amount self.__dict__[key] += amount
def remove(self, key): def remove(self, key):
""" """
Clear a column value in the object. Note that this happens immediately: Clear a column value in the object. Note that this happens immediately:
......
...@@ -359,6 +359,19 @@ class TestQuery(unittest.TestCase): ...@@ -359,6 +359,19 @@ class TestQuery(unittest.TestCase):
self.assertTrue(score.game.objectId) self.assertTrue(score.game.objectId)
#nice to have - also check no more then one query is triggered #nice to have - also check no more then one query is triggered
def testSelectRelatedArray(self):
scores = GameScore.Query.all()
game = Game.Query.all().limit(1)[0]
game.score_array = scores
game.save() # Saved an array of pointers in the game
game = Game.Query.filter(objectId=game.objectId).select_related('score_array')[0]
for score in game.score_array:
self.assertIsInstance(score, GameScore)
self.assertEqual(score.player_name, 'John Doe') # This would trigger a GET if select_related were not used.
#nice to have - also check no more then one query is triggered
def testCanCompareDateInequality(self): def testCanCompareDateInequality(self):
today = datetime.datetime.today() today = datetime.datetime.today()
tomorrow = today + datetime.timedelta(days=1) tomorrow = today + datetime.timedelta(days=1)
......
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