You can use ref.child()
on a nonexistent Child and give a ref.push()
to create.
So just do it:
DatabaseReference empresaRef = ref.child("Empresa");
To access the headquarters:
DatabaseReference sedeRef = empresaRef.child("Sede");
And to create a new one is just:
Empresa empresa = new Empresa();
Sede sede = new Sede();
DatabaseReference empresaRef =
ref.child("Empresa").push().setValue(empresa);
DatabaseReference sedeRef = empresaRef.child("Sede").push().setValue(sede);
However, it is recommended that you save yourself using a unique ID instead of the name.
To generate the ID use:
Empresa empresa = new Empresa();
Sede sede = new Sede();
String empresaID = ref.push().getKey();
DatabaseReference empresaRef = ref.child(empresaID);
empresaRef.setValue(empresa);
String sedeID = empresaRef.push().getKey();
DatabaseReference sedeRef = empresaRef.child(sedeID);
sedeRef.setValue(sede);
;)