File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
+ @file:Suppress(" unused" ) // tested in integration test project
18
+
17
19
package io.objectbox.kotlin
18
20
19
21
import io.objectbox.Box
20
22
import io.objectbox.BoxStore
21
23
import io.objectbox.Property
22
24
import io.objectbox.query.Query
23
25
import io.objectbox.query.QueryBuilder
26
+ import io.objectbox.relation.ToMany
24
27
import kotlin.reflect.KClass
25
28
26
29
inline fun <reified T > BoxStore.boxFor (): Box <T > = boxFor(T ::class .java)
@@ -49,3 +52,19 @@ inline fun <T> Box<T>.query(block: QueryBuilder<T>.() -> Unit) : Query<T> {
49
52
block(builder)
50
53
return builder.build()
51
54
}
55
+
56
+ /* *
57
+ * Allows making changes (adding and removing entities) to this ToMany with a call to
58
+ * [apply][ToMany.applyChangesToDb] the changes to the database.
59
+ * Can [reset][ToMany.reset] the ToMany before making changes.
60
+ * ```
61
+ * toMany.applyChangesToDb {
62
+ * add(entity)
63
+ * }
64
+ * ```
65
+ */
66
+ inline fun <T > ToMany<T>.applyChangesToDb (resetFirst : Boolean = false, body : ToMany <T >.() -> Unit ) {
67
+ if (resetFirst) reset()
68
+ body()
69
+ applyChangesToDb()
70
+ }
You can’t perform that action at this time.
0 commit comments