Skip to content

Commit

Permalink
DOCSP-30345: Update Kotlin SDK's Update page (mongodb#3059)
Browse files Browse the repository at this point in the history
## Pull Request Info

Update existing
[Update](https://www.mongodb.com/docs/realm/sdk/kotlin/realm-database/crud/update/)
page with missing content and improved code examples using updated
object models

### Jira

- https://jira.mongodb.org/browse/DOCSP-30345

### Staged Changes

- [Update - Kotlin
SDK](https://preview-mongodbcbullinger.gatsbyjs.io/realm/docsp-30345-update-page/sdk/kotlin/realm-database/crud/update/)
- add missing sections and update code examples
- [Delete - Kotlin
SDK](https://preview-mongodbcbullinger.gatsbyjs.io/realm/docsp-30345-update-page/sdk/kotlin/realm-database/crud/delete/)
- small updates
- [Supported Types - Kotlin SDK
](https://preview-mongodbcbullinger.gatsbyjs.io/realm/docsp-30345-update-page/sdk/kotlin/realm-database/schemas/supported-types/)-
small updates

### Reminder Checklist

If your PR modifies the docs, you might need to also update some
corresponding
pages. Check if completed or N/A.

- [x] Create Jira ticket for corresponding docs-app-services update(s),
if any
- [x] Checked/updated Admin API
- [x] Checked/updated CLI reference

### Review Guidelines


[REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)
  • Loading branch information
cbullinger authored Nov 8, 2023
1 parent 60532d0 commit 30e51bd
Show file tree
Hide file tree
Showing 22 changed files with 1,183 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,76 +38,6 @@ class Contact : RealmObject {
}

class DataTypesTest : RealmTest() {
@Test
fun createEmbeddedObject() {
runBlocking {
val config = RealmConfiguration.Builder(
setOf(Contact::class, EmbeddedAddress::class)
)
.build()
val realm = Realm.open(config)
realm.write {
val contact = copyToRealm(Contact())
contact.apply {
name = "Nick Riviera"
address = EmbeddedAddress().apply {
street = "123 Fake St"
city = "Some Town"
state = "MA"
postalCode = "12345"
}
}
}

val asyncCall: Deferred<Unit> = async {
val address: EmbeddedAddress = realm.query<EmbeddedAddress>().find().first()
val contact: Contact = realm.query<Contact>().find().first()
// :snippet-start: update-embedded-object
// Modify embedded object properties in a write transaction
realm.write {
// Fetch the objects
val addressToUpdate = findLatest(address) ?: error("Cannot find latest version of embedded object")
val contactToUpdate = findLatest(contact) ?: error("Cannot find latest version of parent object")

// Update a single embedded object property directly
addressToUpdate.street = "100 10th St N"

// Update multiple properties
addressToUpdate.apply {
street = "202 Coconut Court"
city = "Los Angeles"
state = "CA"
postalCode = "90210"
}

// Update property through the parent object
contactToUpdate.address?.state = "NY"
}
// :snippet-end:

// :snippet-start: overwrite-embedded-object
// Overwrite the embedded object in a write transaction
realm.write {
// Fetch the parent object
val parentObject: Contact =
realm.query<Contact>("name == 'Nick Riviera'").find().first()

// Overwrite the embedded object (deletes the existing object)
parentObject.address = EmbeddedAddress().apply {
street = "202 Coconut Court"
city = "Los Angeles"
state = "CA"
postalCode = "90210"
}
}
// :snippet-end:

}
asyncCall.cancel()
realm.close()
Realm.deleteRealm(config)
}
}

@Test
fun queryEmbeddedObject() {
Expand Down
Loading

0 comments on commit 30e51bd

Please sign in to comment.