Skip to content

How can I retreive values from firebase (one to many relationship)?

[![enter image here][

"item03" : {
    "description" : "...... ",
    "image_url" : "....",
    "name" : ".....",
    "price" : "250.00"
item = FirebaseDatabase.getInstance().getReference("Category")
private void fetchData() {
    FirebaseRecyclerOptions<ItemModel> options = new FirebaseRecyclerOptions.Builder<ItemModel>()
            .setQuery(item, new SnapshotParser<ItemModel>() {
        public ItemModel parseSnapshot(@NonNull DataSnapshot snapshot) {
            return new ItemModel(snapshot.child("name").getValue().toString(),

    // Set the adapter
    itemsAdapter = new ItemsRecyclerViewAdapter(options);

I can’t access name, imageurl and other properties because snapshot.getvalue returns true How can I retreive values from firebase having one to many relationship?


You’re trying to read the name, description and other properties from the "item01": true node. That won’t work, since the properties don’t exist on that node.

You’ll instead need to load the snapshot for that specific item, and then read the properties from that. This is fairly non-trivial so I highly recommend using the setIndexedQuery method that was specifically made for this case.