android - Parse one-to-many (array/children) relationship -
i have parent let's call myuser
stored in myuser
, children, post
.
each myuser likes posts. store relationship in array in each myuser.
i want posts user likes:
// given parseobject myuser do: parserelation relation = myuser.getrelation("likedposts"); parsequery<postparseobject> query = relation.getquery(); query.findinbackground(new findcallback< postparseobject >() { @override public void done(list<postparseobject> posts, parseexception e) { if(e==null){ system.out.println("cool"); for(postparseobject post: posts){ //do } } } });
unfortunately above returns 0 posts. in data browser, under myuser's likedposts
column above tested user there 4 linked post-s:
[{"__type":"pointer","classname":"post","objectid":"y3fruwcsph"}, {"__type":"pointer","classname":"post","objectid":"xiljbguids"}, {"__type":"pointer","classname":"post","objectid":"r2uqbl8zrd"}, {"__type":"pointer","classname":"post","objectid":"vmiieljhwf"}]
which means 4 post-s should have been returned in public void done(list<postparseobject> posts, parseexception e) {}
. why that? query one-to-many relationship?
i have "solve puzzle" reading parts of docs. full snippet following. hope finds helpful.
parsequery<myuser> query = parsequery.getquery("myuser"); query.include("likedposts"); query.getinbackground(currentuserid, new getcallback< myuser >() { @override public void done(myuser muser, parseexception e) { arraylist< parseobject > posts = (arraylist< parseobject >) myuser.get("likedposts"); (parseobject post : posts) { //do } });
Comments
Post a Comment