kotlin-extensions / io.realm.kotlin / io.realm.Realm / createEmbeddedObject

createEmbeddedObject

fun <reified T : RealmModel> Realm.createEmbeddedObject(parentObject: RealmModel, parentProperty: String): T

Instantiates and adds a new embedded object to the Realm.

This method should only be used to create objects of types marked as embedded.

Parameters

T - the Class of the object to create. It must be marked with @RealmClass(embedded = true).

parentObject - The parent object which should hold a reference to the embedded object. If the parent property is a list the embedded object will be added to the end of that list.

parentProperty - the property in the parent class which holds the reference.

Exceptions

IllegalArgumentException - if clazz is not an embedded class or if the property in the parent class cannot hold objects of the appropriate type.

Return
the newly created embedded object.