File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
main/kotlin/org/springframework/data/mongodb/core/query
test/kotlin/org/springframework/data/mongodb/core/query Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,17 @@ import kotlin.reflect.KProperty1
22
22
* Abstraction of a property path consisting of [KProperty].
23
23
* @author Tjeu Kayim
24
24
* @author Mark Paluch
25
+ * @author Yoann de Martino
25
26
* @since 2.2
26
27
*/
27
28
class KPropertyPath <T , U >(
28
29
internal val parent : KProperty <U >,
29
30
internal val child : KProperty1 <U , T >
30
- ) : KProperty<T> by child
31
+ ) : KProperty<T> by child {
32
+ override fun toString (): String {
33
+ return asString(this )
34
+ }
35
+ }
31
36
32
37
/* *
33
38
* Recursively construct field name for a nested property.
@@ -45,7 +50,7 @@ internal fun asString(property: KProperty<*>): String {
45
50
* Builds [KPropertyPath] from Property References.
46
51
* Refer to a field in an embedded/nested document.
47
52
*
48
- * For example, referring to the field "book. author":
53
+ * For example, referring to the field "author.name ":
49
54
* ```
50
55
* Book::author / Author::name isEqualTo "Herman Melville"
51
56
* ```
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import org.junit.Test
20
20
21
21
/* *
22
22
* @author Tjeu Kayim
23
+ * @author Yoann de Martino
23
24
*/
24
25
class KPropertyPathTests {
25
26
@@ -60,6 +61,26 @@ class KPropertyPathTests {
60
61
assertThat(property).isEqualTo(" entity.book.author.name" )
61
62
}
62
63
64
+ @Test
65
+ fun `Convert nested KProperty to field name using toString()` () {
66
+
67
+ val property = (Book ::author / Author ::name).toString()
68
+
69
+ assertThat(property).isEqualTo(" author.name" )
70
+ }
71
+
72
+
73
+ @Test
74
+ fun `Convert triple nested KProperty to field name using toString()` () {
75
+
76
+ class Entity (val book : Book )
77
+ class AnotherEntity (val entity : Entity )
78
+
79
+ val property = (AnotherEntity ::entity / Entity ::book / Book ::author / Author ::name).toString()
80
+
81
+ assertThat(property).isEqualTo(" entity.book.author.name" )
82
+ }
83
+
63
84
class Book (val title : String , val author : Author )
64
85
class Author (val name : String )
65
86
}
You can’t perform that action at this time.
0 commit comments