Realm v1.0.0 の時点 (およびおそらくそれ以前) では、RealmObjectSchema#addRealmListField(String, RealmObjectSchema)
( javadoc へのリンク) を呼び出すだけでこれを実現できます。たとえば、permissions
タイプのフィールドをRealmList<Permission>
クラスUser
に追加しようとしている場合は、次のように記述します。
if (!schema.get("User").hasField("permissions")) {
schema.get("User").addRealmListField("permissions", schema.get("Permission"));
}
Realm の移行ドキュメントhereにも例があります。addRealmListField
便宜上、の完全な javadoc を次に示します。
/**
* Adds a new field that references a {@link RealmList}.
*
* @param fieldName name of the field to add.
* @param objectSchema schema for the Realm type being referenced.
* @return the updated schema.
* @throws IllegalArgumentException if the field name is illegal or a field with that name already exists.
*/