File tree Expand file tree Collapse file tree
objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17+ @file:Suppress(" unused" ) // tested in integration test project
18+
1719package io.objectbox.kotlin
1820
1921import io.objectbox.Box
2022import io.objectbox.BoxStore
2123import io.objectbox.Property
2224import io.objectbox.query.Query
2325import io.objectbox.query.QueryBuilder
26+ import io.objectbox.relation.ToMany
2427import kotlin.reflect.KClass
2528
2629inline 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> {
4952 block(builder)
5053 return builder.build()
5154}
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