Commit 928d4ee9 by David Robinson

Merge pull request #121 from felipe-lavratti/convert_array_to_object

Added automatic conversion of array of pointers to parse object 
parents 15faf6bd 05c4ffd8
......@@ -35,6 +35,8 @@ class ParseType(object):
@staticmethod
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
if isinstance(parse_data, dict):
......@@ -455,7 +457,7 @@ class Object(six.with_metaclass(ObjectMetaclass, ParseResource)):
}
self.__class__.PUT(self._absolute_url, **payload)
self.__dict__[key] += amount
def remove(self, key):
"""
Clear a column value in the object. Note that this happens immediately:
......
......@@ -359,6 +359,19 @@ class TestQuery(unittest.TestCase):
self.assertTrue(score.game.objectId)
#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):
today = datetime.datetime.today()
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