I have a Contact
model which holds different attributes and lists of attributes. Now i want to store these in Firestore but with the lists as subcollections of the respective document.
A minimal example of the Contact
model looks like this (note that the list is excluded from the map):
class Contact(private val map: MutableMap<String, Any?>){
var nameDisplay:String? by map
var nickname:String? by map
var organisation:String? by map
val phones:ArrayList<Phone> = ArrayList()
}
With this representation in Firestore:
contacts:
contact1
nameDisplay = "Test"
nickname = "Test"
organisation = "some corp"
phones:
phone1
number = 8243525
label = "this guy"
phone2
number = 8243525433
label = "this guy"
contact2
....
I am looking for a way to best implement this behavior.
A working solution i found is with a secondary constructor where i can pass the collections seperately.
A desired implementation would be the default implementation for custom objects but with the above behavior:
var contact: Contact = documentSnapshot.toObject(Contact::class.java);