milesrichardson / ParsePy

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

Add Relation Query #55

Closed folse closed 8 years ago

folse commented 10 years ago

Now it support relation query:

place = Place.Query.get(objectId="sscyMpfZJ2")
categorys = Category_Place.Query.relation_filter(category__relation=place)._relation_fetch()
print categorys

equal to :

import json,httplib,urllib
connection = httplib.HTTPSConnection('api.parse.com', 443)
params = urllib.urlencode({"where":json.dumps({
        "$relatedTo": {
        "object": {
        "__type": "Pointer",
        "className": "Place",
        "objectId": "sscyMpfZJ2"
        },
        "key": "category"
    }
    })})
connection.connect()
connection.request('GET', '/1/classes/Category_Place?%s' % params, '', {
        "X-Parse-Application-Id": "MQRrReTdb...",
        "X-Parse-REST-API-Key": "44mp6LNg..."
    })
resp = connection.getresponse().read()
result = json.loads(resp)
print result
lullis commented 10 years ago

It seems to do what is intended, but I really have to -1 for the API. The relation classes are defined by Parse explicitily as way to provide many-to-many queries, why can't our library be modelled after common ORM's?

milesrichardson commented 8 years ago

better PR in #131