I am developing an android native application with Kotlin and Firebase , I have a collection named Topic and 2 fields of type reference one for User and the other for Category , I was trying to get all documents also with the reference document , but it does not seem to work:
db.collection("topic").get().addOnSuccessListener { result ->
for (document in result) {
Log.e("success", "${document.id} => ${document.data.get("subject")}")
var topic: Topic = Topic(
document.id as String,
document.data.get("subject") as String,
document.data.get("content") as String,
document.data.get("created_at") as String,
document.getDocumentReference("Category") as Category,
document.getDocumentReference("User") as User
)}
No error , but no result either in my print(topic) .
This is Topic Class
class Topic : Serializable {
var id : String = ""
var subject : String = ""
var content : String = ""
var created_at : String = ""
var cat = Category()
var user = User()
constructor(){}
constructor(
id: String,
subject: String,
content: String,
created_at: String,
cat: Category,
user: User
) {
this.id = id
this.subject = subject
this.content = content
this.created_at = created_at
this.cat = cat
this.user = user
}
override fun toString(): String {
return "Topic(id='$id', subject='$subject', content='$content', created_at='$created_at', cat=$cat, user=$user)"
}
}