In my flutter application, I'd like to keep track of the employee location for different companies without having to flatten the database (see architecture below).
Q1 : If I set a listener on an office node, is there a way to get the parents nodes from the event ?
Q2 : if a new company node is created in the database, how can I attach dynamically a new listener on the office's new company ?
_employeesQuery = databaseReference.reference().child("Company_1/Office_1");
_onEmployeeAddedSubscription =
_employeesQuery.onChildAdded.listen(onEmployeeAdded);
...
onEmployeeAdded(Event event) {
setState(() {
String name = event.snapshot.key;
print("New employee added $name in Office ?? in Company ??");
});
}