0

Let's say that we have a structure like this:

project:[
    1:{
        title: 'test'
        description: 'hello'
        category_id: 2
    }
]
category:[
    1: {
        name: 'motorcycles' 
    },
    2: {
        name: 'cars'
    }
]

How can I load category name when I fetch the project from the firebase database?

To fetch projects I do something like this: db.list('/project'); where db is of type AngularFireDatabase.

Angular4, angularfire2

Tarida George
  • 1,303
  • 3
  • 17
  • 36
  • Don't store categories in an array, store them in a set. See my explanation here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Oct 08 '17 at 17:41
  • 1
    Aside from that you'll need to load the categories separately from the client what's known as a client-side join. If the list of categories is not too long, you can load them all on start-up, otherwise you'll have to load them as you're pulling in the project(s). See https://stackoverflow.com/questions/38421551/joining-flattened-data – Frank van Puffelen Oct 08 '17 at 17:42

0 Answers0