由于 Realm 实体中的伴随对象,我面临一个问题。
例子:
// Entity
open class MyEntity(
@PrimaryKey
var id: String? = "",
// other fields...
): RealmObject() {
companion object{
fun clean(realm: Realm) {
realm.beginTransaction()
realm.where(MyEntity::class.java).findAll().deleteAllFromRealm()
realm.commitTransaction()
}
}
}
// Migration code
schema
.create(MyEntity.class.getSimpleName())
.addField("id", String.class, FieldAttribute.PRIMARY_KEY);
addMissingFields(schema, MyEntity.class);
执行迁移时,出现以下异常:
Realm doesn't support this field type: Companion(class com.example.MyEntity$Companion)
我想知道如何忽略companion object
来自领域的扫描。