How to query value of column that is set as pointer to other table in Parse
Solution 1
Here is the solution to this one:
First you need to create a ParseObject
from the type of your table:
ParseObject sale = ParseObject.createParseObject("Sale");
Then you need to get the ParseObject
from the result:
sale = result.getParseObject(pointer_field);
Now you can pull from sale
any field that it has just as you would do it normally, for example:
sale.getString("some_field")
Note: When you are doing your query you must to include the pointer field if you want to be able to extract the data from it after the query will be returned. The result:
query.include("pointer_field")
Hope it helps
Solution 2
@Akshat Agarwal, here is a example in JavaScript:
var parseObj = Parse.Object.extend('parseObj');
new Parse.Query(parseObj)
.include('pointerField')
.find(function (data) {
data.get('pointerField').get('fieldName');
});
vlio20
Updated on June 09, 2022Comments
-
vlio20 almost 2 years
I am using Parse for my app. I want to query a table with column that set to be a pointer to other table. Here is the query:
ParseQuery query = new ParseQuery("CategoryAttribute"); query.whereEqualTo("categoryId", categoryId); query.findInBackground(new FindCallback() { @Override public void done(List<ParseObject> categoryAttributes, ParseException e) { if (e == null) { for (int i = 0; i < categoryAttributes.size(); i++){ String atributeCategoryId = categoryAttributes.get(i).getString("categoryId"); String attributeKey = categoryAttributes.get(i).getString("attributeKey"); String attributeValue = categoryAttributes.get(i).getString("attributeValue"); setCategoryAtributeRow(atributeCategoryId, attributeKey, attributeValue); } } else { Log.d("score", "Error: " + e.getMessage()); } } });
So the
categoryId
column is a pointer to other table. Other columns work fine. I tried to scan the API and the guides but couldn't find needed solution. Help would be much appreciated!-
Jaffar Raza almost 11 yearsHave you find any solution of this
-
-
vlio20 almost 11 years@Jaffar Raza here is the answer
-
Akshat Agarwal over 10 yearsCould you give a hint on how to do this using javascript?
-
vlio20 about 10 years@AkshatAgarwal, Sorry I don't know how to do this in javascript. But I am sure it is very similar.
-
vaibhav almost 9 yearscan't get you !!! see i have a field username that is pointer to "User" and i want to query it with that pointer only !! can you suggest me ?????
-
jean d'arme almost 9 yearsThey should have included it in their documentation! Great solution!