【问题标题】:Realm doesn't support this field type: CompanionRealm 不支持此字段类型:Companion
【发布时间】:2020-12-23 14:19:33
【问题描述】:

由于 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)

我想知道如何从 Realm 扫描中忽略 companion object

【问题讨论】:

    标签: android kotlin realm realm-java


    【解决方案1】:

    使用Realm的注解@Ignore

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多