@@ -31,14 +31,29 @@ private class KPropertyPath<T, U>(
31
31
val child : KProperty1 <U , T >
32
32
) : KProperty<T> by child
33
33
34
+ /* *
35
+ * Abstraction of a property path that consists of parent [KProperty],
36
+ * and child property [KProperty], where parent [parent] has an [Iterable]
37
+ * of children, so it represents 1-M mapping, not 1-1, like [KPropertyPath]
38
+ *
39
+ * @author Mikhail Polivakha
40
+ */
41
+ internal class KIterablePropertyPath <T , U >(
42
+ val parent : KProperty <Iterable <U ?>? >,
43
+ val child : KProperty1 <U , T >
44
+ ) : KProperty<T> by child
45
+
34
46
/* *
35
47
* Recursively construct field name for a nested property.
36
48
* @author Tjeu Kayim
49
+ * @author Mikhail Polivakha
37
50
*/
38
51
internal fun asString (property : KProperty <* >): String {
39
52
return when (property) {
40
53
is KPropertyPath <* , * > ->
41
54
" ${asString(property.parent)} .${property.child.name} "
55
+ is KIterablePropertyPath <* , * > ->
56
+ " ${asString(property.parent)} .${property.child.name} "
42
57
else -> property.name
43
58
}
44
59
}
@@ -55,5 +70,32 @@ internal fun asString(property: KProperty<*>): String {
55
70
* @author Yoann de Martino
56
71
* @since 2.5
57
72
*/
73
+ @JvmName(" div" )
58
74
operator fun <T , U > KProperty<T?>.div (other : KProperty1 <T , U >): KProperty <U > =
59
75
KPropertyPath (this , other)
76
+
77
+ /* *
78
+ * Builds [KPropertyPath] from Property References.
79
+ * Refer to a nested property in an embeddable or association.
80
+ *
81
+ * Note, that this function is different from [div] above in the
82
+ * way that it represents a division operator overloading for
83
+ * child references, where parent to child reference relation is 1-M, not 1-1.
84
+ * It implies that parent has an [Iterable] or any liner [Collection] of children.
85
+ **
86
+ * For example, referring to the field "addresses.street":
87
+ * ```
88
+ * User::addresses / Author::street contains "Austin"
89
+ * ```
90
+ *
91
+ * And the entities may look like this:
92
+ * ```
93
+ * class User(val addresses: List<Address>)
94
+ *
95
+ * class Address(val street: String)
96
+ * ```
97
+ * @author Mikhail Polivakha
98
+ */
99
+ @JvmName(" divIterable" )
100
+ operator fun <T , U > KProperty<Iterable<T?>?>.div (other : KProperty1 <T , U >): KProperty <U > =
101
+ KIterablePropertyPath (this , other)
0 commit comments