I would like to save 2 different objects that share some attributes in the same collection. I defined my models using the recommended pattern for such case:
@ParseClassName("BusinessAd")
open class BusinessAd: ParseObject() {
val advertiser by ParseDelegate<Advertiser>()
var viewsCount by intAttribute()
var clicksCount by intAttribute()
class Banner: BusinessAd() {
var image by ParseDelegate<ParseFile>()
}
class Post: BusinessAd() {
var description by stringAttribute()
var attachments by ParseDelegate<List<ParseFile>>()
}
}
But it looks like this is not possible. Because when I try to register each one of them
ParseObject.registerSubclass(BusinessAd.Banner::class.java)
ParseObject.registerSubclass(BusinessAd.Post::class.java)
I receive this error
java.lang.IllegalArgumentException: Tried to register both sy.edu.uok.admooncore.models.BusinessAd$Banner and sy.edu.uok.admooncore.models.BusinessAd$Post as the ParseObject subclass of BusinessAd. Cannot determine the right class to use because neither inherits from the other.`
I really would like to to do it this way to benifit from kotlin language features. I can still do it by define a one giant subclass but with nullable fields and then I have to manually check for the type of the objects which is not ideal
Any thoughts about this. Does it contradict with Parse concepts about how we store data or it’s legitimate use case