Skip to content

Commit c273976

Browse files
committed
Fix Results nofitifation for changes to nested collections
1 parent 29044d7 commit c273976

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Query with @type does not support filtering on collections ([#7281](https://github.com/realm/realm-core/issues/7281), since 14.0.0-beta.0)
1717
* Query involving string operations on nested collections would not work ([#7282](https://github.com/realm/realm-core/issues/7282), since 14.0.0-beta.0)
1818
* Using ANY, ALL or NONE in a query on nested collections would throw an exception ([#7283](https://github.com/realm/realm-core/issues/7283), since 14.0.0-beta.0)
19+
* Results notifications does not report changes to inner collections ([#7335](https://github.com/realm/realm-core/issues/7335), since 14.0.0-beta.0)
1920

2021
### Breaking changes
2122
* If you want to query using @type operation, you must use 'objectlink' to match links to objects. 'object' is reserved for dictionary types.

src/realm/object-store/impl/results_notifier.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ void ListResultsNotifier::run()
393393
std::iota(m_run_indices->begin(), m_run_indices->end(), 0);
394394
}
395395

396+
if (m_change.paths.size()) {
397+
if (auto coll = dynamic_cast<CollectionParent*>(m_list.get())) {
398+
for (auto& p : m_change.paths) {
399+
// Report changes in substructure as modifications on this list
400+
auto ndx = coll->find_index(p[0]);
401+
if (ndx != realm::not_found)
402+
m_change.modifications.add(ndx); // OK to insert same index again
403+
}
404+
}
405+
}
406+
396407
calculate_changes();
397408
}
398409

test/object-store/list.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,11 +1356,19 @@ TEST_CASE("nested List") {
13561356
}
13571357

13581358
SECTION("inserting in sub structure sends a change notifications") {
1359+
// Check that notifications on Results are correct
1360+
Results res = lst0.as_results();
1361+
CollectionChangeSet change1;
1362+
auto token_res = res.add_notification_callback([&](CollectionChangeSet c) {
1363+
change1 = c;
1364+
});
1365+
13591366
auto token = require_change();
13601367
write([&] {
13611368
lst0.get_dictionary(0).get_list("list").add(Mixed(42));
13621369
});
13631370
REQUIRE_INDICES(change.modifications, 0);
1371+
REQUIRE_INDICES(change1.modifications, 0);
13641372
REQUIRE(!change.collection_was_cleared);
13651373
}
13661374

0 commit comments

Comments
 (0)