parent

fun <T : TypedRealmObject> EmbeddedRealmObject.parent(parentClass: KClass<T>): T

Gets the parent of the embedded object, embedded objects always have an unique parent, that could be a RealmObject or another EmbeddedRealmObject.

If known, the type parameter can be used to cast it to the parent type. The other approach is to cast it to the generic TypedRealmObject and then switch over its possible types:

val parent: TypedRealmObject = child.parent()
when(parent) {
is Parent1 -> TODO()
is Parent2 -> TODO()
is EmbeddedParent1 -> TODO()
else -> TODO()
}

Return

parent of the embedded object.

Parameters

T

parent type.

parentClass

parent KClass.

inline fun <T : TypedRealmObject> EmbeddedRealmObject.parent(): T

Returns a TypedRealmObject that represents the parent that hosts the embedded object.

Reified convenience wrapper for EmbeddedRealmObject.parent.