I have three parse subclasses: Recipe, Ingredient, and RecipeIngredient. RecipeIngredient has a pointer to a Recipe, and a pointer to an Ingredient.
When I am trying to create a QueryFactory to get all the ingredients for a recipe. I am trying to do this with whereMatchesKeyInQuery, but the objectIds aren't matching. From the docs, it appears that this should be legal. What am I missing?
public MeatIngredientListAdapter(Context context, final String recipeName) {
super(context, new ParseQueryAdapter.QueryFactory<Ingredient>() {
public ParseQuery<Ingredient> create() {
ParseQuery<Ingredient> query = ParseQuery.getQuery(Ingredient.class);
query.whereEqualTo("isMeatOrFat", true);
ParseQuery<RecipeIngredient> riQuery = ParseQuery.getQuery(RecipeIngredient.class);
riQuery.whereEqualTo("recipeName", recipeName);
riQuery.include("ingredient");
riQuery.whereEqualTo("isMeatOrFat", true);
query.whereMatchesKeyInQuery("objectId", "ingredient.objectId", riQuery);
return query;
}
});
}
In your case the use of
whereMatchesKeyInQuery
is overkill. I might not have enough information to make this call about your app but is seems that you would be able to cut out the need forRecipeIngredient
all together if you just create aRelation
of theIngredient
class inside theRecipe
class. This will simplify your queries and make your app more scalable and give you features (explained below). If you had a data structure like this:Now you can store one recipe that "points" (using relations) to many ingredients.
So an example entry might look like this:
And here in code we add the data to the classes:
The magic behind this setup is that we can now specify a recipe by name and get all ingredients like you wanted but we can also retrieve all recipes that have certain ingredient(s) in them (this is the beauty of a many-to-many relationship) and on top of that it simplifies your queries.
Now for the original query you wanted with this new setup:
query
will hold all of the ingredients for therecipe
object when the query is executed.Now suppose you want to create a query where you get all of the recipes that contain a certain ingredient:
query
will contain all Recipe objects that have the specified ingredient in theiringredients
relation column when the query is executed.I hope this helped you. Please let me know if I severely misunderstood the structure of your app - if so I will revise my answer if you give me new information but honestly I think the "middle man"
RecipeIngredient
is forcing you to complicate your app.