Skip to content

Commit

Permalink
Add tests for persisted name links in lists (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech authored Aug 1, 2023
1 parent 6322233 commit 311a6ae
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,27 @@ class PersistedNameTests {
realm.writeBlocking {
copyToRealm(
Parent().apply {
this.child = Child()
this.child = Child().apply { name = "child1" }
this.children.add(
Child().apply {
name = "first-child"
children.add(
Child().apply { name = "first-grand-child" }
)
}
)
}
)
}

assertEquals(1, realm.query<Parent>().count().find())
assertEquals(1, realm.query<Child>().count().find())
assertEquals(3, realm.query<Child>().count().find())

assertEquals("child", realm.query<Parent>().first().find()!!.child!!.name)
val parent = realm.query<Parent>().first().find()!!
assertEquals("child1", parent.child!!.name)
val child2 = parent.children.first()
assertEquals("first-child", child2.name)
assertEquals("first-grand-child", child2.children.first().name)
}
}

Expand Down Expand Up @@ -507,9 +519,14 @@ class RealmChild(var id: Int) : RealmObject {
class Parent : RealmObject {
var name = "parent"
var child: Child? = null

@PersistedName("renamedChildren")
var children: RealmList<Child> = realmListOf()
}

@PersistedName(name = "RenamedChild")
class Child : RealmObject {
var name = "child"
@PersistedName("renamedChildren")
var children: RealmList<Child> = realmListOf()
}

0 comments on commit 311a6ae

Please sign in to comment.