Do a join or relationship in Firebase and Angular2

0

What kind of friends, I have this following problem, it happens that I have 2 tables in firebase which I would like you to share data, this is matrices of the db:

    clientes: {
        1: {
            nombre: "Juan";
            empresas: {
                emp1: true;
                emp2: true;
            }
        }

        2: {
            nombre: "Carlos";
            id_empresa: "emp2";
            empresas: {
                emp2: true;
            }
        }
    }
    empresas: {
        emp1: {
            nombre_empresa: "Empresa 1";   
        }
        emp2: {
            nombre_empresa: "Empresa 2";
        }
    }

I would like to know how to make a union of these tables: This is the code but it still does not work, am I on track ?:

getClientes () {
    return this.afoDatabase.list('/clientes')
        .map ( items => {
             return items.map ( item => {
               item.nombreEmpresa = this.afoDatabase.object('empresas' + item.$key + '/nombre')
                   .subscribe( data => {
                       return data;   
                   });
             });
        });
}
    
asked by Alain 17.01.2018 в 19:40
source

1 answer

0

At first glance, you have a problem in the second consultation

item.nombreEmpresa = this.afoDatabase.object('empresas' + item.$key + '/nombre')

The problem is that when the string for the queryObject happens to be generated, something like that remains

item.nombreEmpresa = this.afoDatabase.object('empresas1234asdfg123/nombre')

you still have to add the / between the string companies and the key, leaving item.nombreEmpresa = this.afoDatabase.object('empresas/' + item.$key + '/nombre')

And with that you should not have any kind of problem

    
answered by 19.01.2018 в 22:24