数据库关系
有一个小组
DYNAMICGROUPS
- >具有指针列的列(成员) - >包含array of user's objectId
。现在我想在DYNAMICGROUPS
中应用查询以获取dynamicGroups
的所有详细信息以及成员列的各个指针的所有对象详细信息。现在我正在从多个查询中做,但它的创建问题是:Synchronous issue code
final ArrayList<TempGroupClass> tempGroupList = new ArrayList<TempGroupClass>();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username",
SharedPreferencesClass.getUserName(context));
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> arg0, ParseException arg1) {
if (arg1 == null) {
if(arg0.size() > 0) {
Log.d(TAG, "getUpdatedRecordsFromParse");
ParseQuery<ParseObject> query = ParseQuery.getQuery("DynamicGroup");
ArrayList<String> array = new ArrayList<String>();
array.add(arg0.get(0).getObjectId());
query.whereContainedIn("members", array);
query.include("code");
query.include("members");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> arg0, ParseException arg1) {
if (arg1 == null) {
if (arg0.size() > 0) {
for (int i = 0; i < arg0.size(); i++) {
TempGroupClass temp = new TempGroupClass();
ArrayList<String> friendListArray = new ArrayList<String>();
**<!-- arg0.get(i).getList("members") this is giving me array of pointers now i want object details of every pointer but how ? -->**
// now to get dynamic group members array
// loop through every member and
for (int j = 0; j < arg0.get(i).getList("members").size(); j++) {
// here we are excluding our object id from members id recieved from parse
if (!(SharedPreferencesClass.getUserObjectId(context)
.equalsIgnoreCase(arg0.get(i).getList("members").get(j).toString()))) {
// friendarraylist excluding our objectID
friendListArray.add(arg0.get(i).getList("members").get(j).toString());
}
}
temp.setParseObjectId(arg0.get(i).getObjectId());
temp.setFriendObjectIdList(friendListArray);
// now get information of groups from groupCode
Log.d(TAG,"setFriendObjectIdList size:" + temp.getFriendObjectIdList().size());
/****************now get group code information start *******************/
ParseObject objectCodeObj = new ParseObject("DynamicGroup");
objectCodeObj = arg0.get(i).getParseObject("code");
String groupTitle = objectCodeObj.getString("code");
// Pointor Object value Log.d(TAG,"GROUP CODE STRING :" + groupTitle);
Log.d(TAG, "GROUP CODE EXPIRES TIME :" + objectCodeObj.getDate("expires"));
/*****now get group code information stop ***********/
// loop for testing purpose what we r getting in list
for(int j = 0; j < temp.getFriendObjectIdList().size(); j++) {
Log.d(TAG,"member id:"+temp.getFriendObjectIdList().get(j));
}
temp.setGroupTitle(groupTitle);
temp.setExpires(objectCodeObj.getDate("expires"));
tempGroupList.add(temp);
}
getRecords(tempGroupList);
} else {
Log.d(TAG, "DynamicGroup arg0.size else :" + arg0.size());
}
}
// Log.d(TAG,"returned Group List size 1:" + tempGroupList.size());
}
});
} else {
Log.d(TAG,"user arg0.size:"+arg0.size());
}
}
}
});
如果我按照上述方法进行操作,那么我也会在下一个查询中遇到问题,那么我应该如何编写查询并立即获取所有对象详细信息,然后保存在local / temp {{1 }?
表格结构:
为dynamicGroup
GroupCode
用户表
答案 0 :(得分:2)
您的“成员”列不是指针数组,它是一个字符串对象ID的数组。如果您实际上已将它们设置为指针,则这是一个具有一个include('members')
约束的简单单个查询。
将对象保存到数组列时,不要保存对象id,保存整个对象......它将转换为指针。
您可以手动编辑阵列,例如,更改:
["iHHyf1Rerw", "sFqTz7FHCJ", "fxZ0GXOtrn"]
为:
[{"__type":"Pointer","className":"_User","objectId":"iHHyf1Rerw"},{"__type":"Pointer","className":"_User","objectId":"sFqTz7FHCJ"},{"__type":"Pointer","className":"_User","objectId":"fxZ0GXOtrn"}]
如果您已经错误配置了大量数据,则可以使用adhoc后台作业来更新所有数据。
答案 1 :(得分:0)
我认为@Fosco对json的看法是,如果你想手动插入。 从你的代码中你应该保存到孔对象的数组,而不是它们的id。