Reputation: 11
This is my firebase database structure in the image :
I'll explain the structure aswell, I have a forum, which people can post trades in. Every post has some random user key as you can see in the picture. Also every post has a list of items which the user wants to sell or buy ('have' or 'want', in the image). the number of items in each trade can change from 1 to 10.
I want to fetch all of the forum posts of the users that are selling ( or buying ) with some item id.
For example : Get forum posts of users selling items with 'Id' of 'Some Item Name'
How do I do this? I can't seem to get reference to each item in the inventory since you can't do multiple orderByChild. If you think it's impossible with this DB structure, Please offer me an alternative. I want to know whether I'm wasting my time with firebase and this is impossible to do :(
Please note that I have a lot of data in my DB so I can't just filter the posts on the client side.
Upvotes: 0
Views: 307
Reputation: 346
Either you can change your database structure OR You can create a different node which can contain the metadata of all the "have" OR "want" items with the itemID, userID and "have" or "want" node child number(in this case it should be 0-9, as there are 10 items in each type). So whenever you are saving/deleting you data from "have" or "want" section you have to do the same operation in the other new metadata table also.
You can run your query on this node to get the desired item and then with the help of result data you get those particular items directly by creating a reference at runtime as you are having userId, have or want type, itemId.
your metadata should be something like.
metadata
|
|
+{randonId1}
|
|-type : "have" or "want"
|-userId : "randonId of user".(Kt0QclmY3.as shown in picture)
|-Id: "Breakout Type-S"
|-childOnNode: 0, (0-9)
+{randonId2}
|
|-type : "have" or "want"
|-userId : "randonId of user".(Kt0R48Cp..as shown in picture)
|-Id: "Breakout"
|-childOnNode: 0, (0-9)
Upvotes: 1