I'm having trobule with adding Array of Objects (tables) to Array of objects(restaurants). By that i mean, that I have following Firestore structure:
... (other data)
restaurants: [
0: {
name: name_0
...
tables: [
0: { no_chairs: 5, ... },
]
},
...
]
I know how to add new object to restaurants, but I'm having trouble with adding new restaurant if tables list contains any data.
My code rn:
var collection = firestore.collection('usersData')
.doc(this.currentUser.uid).collection('buisness').doc('restaurants');
collection.update({
'restaurants': FieldValue.arrayUnion([restaurant.toJson()]),
}).then( ... // reaction based on api answer
class Restaurant:
Map<String, dynamic> toJson() => {
'name': name,
...
'tables': tables!=null? [tables] : [], // I think that I should modify this line
};
class Table:
Map<String, dynamic> toJson()=> { // Or this method / use another
'no_chairs': no_chairs,
...
};
Is there any simple way to do it? Preferably without modyfing firestore file structure, but if it is necessary I'm willing to do it.
Extra question: How to modify object in tables list? For example I want to change no_chairs to 7