我使用Parse.com,我有2个表:食谱和成分,
现在在1个食谱中我有很多成分
在解析中我使用成分表中的父连接表,我正在尝试构建Recige的ArrayList
(每个配方包含成分的ArrayList)
这样的事情:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Recipe");
query.orderByDescending("createdAt");
query.include("Ingredient");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> RecipeList, ParseException e) {
//What should i write here ???
------------------------------
}
非常感谢
配料表: ObjectID,NAME,UNIT,parent
答案 0 :(得分:1)
由于成分只属于食谱清单,我认为收件人可以参考属于他们列表的成分。
如果您的参考是指向配方的所有成分的指针,那么这应该足够了
ParseQuery<ParseObject> query = ParseQuery.getQuery("Recipies");
query.include("ingredients"); //Name of your ingredients table
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for(int index = 0; index < objects.size(); i++){
objects.get(i); //This is a recipe
objects.get(i).get("name of the column that hold the pointer"); //This is your ingredient
}
} else {
Log.e("", e.getMessage());
}
functionCallback.done(objects, e);
}
});
有关'include'查询的更多信息,请访问here(在关系查询下)
如果您将引用存储在数组中,您可以尝试执行类似这样的操作
ParseQuery<ParseObject> ingredientQuery = ParseQuery.getQuery("ingredients");
ParseQuery<ParseObject> query = ParseQuery.getQuery("Recipies");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for(int index = 0; index < objects.size(); i++){
objects.get(i); //This is a recipe
String[] pointers = objects.get(i).get("name of the column that hold the pointer");
//This is your ingredient reference (if you did 'recipe.put("ingredients", ingredient);',
//the reference that would be saved is the id of the ingredient.
ingredientsQuery.whereContainedIn("objectId", pointers);
ingredientsQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> ingredients, ParseException e) {
if (e == null) {
for(int index = 0; index < ingredients.size(); i++){
ingredients.get(i); //This is a ingredient
}
} else {
Log.e("", e.getMessage());
}
}
} else {
Log.e("", e.getMessage());
}
functionCallback.done(objects, e);
}
});
认为应该这样做!