0

I have a database that looks like this: db

and i'm using FirebaseRecyclerAdapter to show all on a screen, and i wanted to make a search by ingredients, so i tried to pass the FirebaseRecyclerAdapter a query, where "recipe" is some recipe(in the db image, it's the 1VS..) and search is some ingredient that i type(for example, Cocoa). but the adapter says i cannot convert "String" to "Recipe" (which is my model that i'm passing to the FirebaseRecycler) because it thinks that i'm trying to just order by ingredients and not the recipes themselves, and idea how i can solve this issue? thanks.

Query searchRecipesQuery = recipeRef.child(recipe).child("ingredients").orderByValue().startAt(search).endAt(search + "\uf8ff");
            FirebaseRecyclerOptions<Recipe> options = new FirebaseRecyclerOptions.Builder<Recipe>()
                    .setQuery(searchRecipesQuery, Recipe.class).build();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
neorus
  • 477
  • 1
  • 6
  • 19
  • 2
    There is no way to get a list of recipes that have a specific ingredient with a single query in your current data structure. See https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value and https://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Jan 04 '19 at 21:52
  • hmm i see.. any idea how to change the db structure to make it work? – neorus Jan 04 '19 at 21:55
  • Did you check out the links I gave? Because my answers there should be pretty instructional. – Frank van Puffelen Jan 04 '19 at 21:58
  • i did, they say a lot of good rules, but they not really helped me to think of a better way to structure my db(and the second link i'm not really sure even describes my problem) – neorus Jan 05 '19 at 11:44

0 Answers0