anand
anand

Reputation: 1751

Retrieve the data from the relationship in parse DB through Rest API

I am been going through the parse DB but got stuck at one issue. The issue is How can I retrieve the data from the relationship in parse DB.

For ex: I have two table

Department table structure is:

Employee table structure is:

In the Employee table i have created one column with department and added the relation With Department table. I have successfully added the records and created a relation. And when i am clicking on View Relation in department column i am getting the data for the associated Department.

I have given the curl command to get the data:

Curl -X GET <my application Id> <my rest api key>
https://api.parse.com/1/classes/Employee

I am getting the result as

{"results":[{"department":{"__type":"Relation","className":"Department"},"createdAt":"2015-08-07T08:53:23.220Z","objectId":"AkceV0fwW","updatedAt":"2015-08-07T09:04:45.362Z","userName":"XYZ"}]}

Now how to retrieve the objectId of the Department in this result means I want to get the department name for this Employee.

Upvotes: 3

Views: 802

Answers (1)

Wain
Wain

Reputation: 119031

Department class doesn't have an objectId, instances of that class do, and your statement means you're thinking about the relationship query backwards.

The relation holds multiple instances (potentially). If you just want one then you should use a pointer as it's much easier.

With a relation you use the objectId of the container and the name of the relation to do a query on the contained class:

GET https://api.parse.com/1/classes/Department

'where={"$relatedTo":{"object":{"__type":"Pointer","className":"Employee","objectId":"AkceV0fwW"},"key":"department"}}'

Upvotes: 2

Related Questions