I have a method that creates and update a realm table
private static void createOrUpdateModel(RealmSchema schema, Class clazz) {
Field field[] = clazz.getDeclaredFields();
String clazzName = clazz.getSimpleName();
Log.e("Class name", clazzName);
RealmObjectSchema objectSchema = schema.get(clazzName);
if (objectSchema == null) {
objectSchema = schema.create(clazzName);
Log.e("Created :", clazzName);
}
for (Field mField: field) {
if (!objectSchema.hasField(mField.getName())) {
objectSchema.addField(mField.getName(), mField.getType());
Log.e(mField.getName().concat(" "), mField.getType().getSimpleName());
}
}
}
But in one of the fields in my table is a realmObject. This is the model class
public class NimcKeyDetailsModel extends RealmObject {
@PrimaryKey
private String applicationId;
private String credentialData;
private CenterModel centerModel;
}
CenterModel is a realm object. now I am getting this error
Use 'addRealmObjectField()' instead to add fields that link to other RealmObjects: centerModel(class com.seamfix.nimc_sdk.models.CenterModel)
So what I did was to check if the field type is of type realmObject then I use the addRealmObjectField() if not then addField. But still didn't work, please is there a workaround this?