Skip to content

Commit

Permalink
Fix Results nofitifation for changes to nested collections
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Feb 15, 2024
1 parent 29044d7 commit c273976
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Query with @type does not support filtering on collections ([#7281](https://github.com/realm/realm-core/issues/7281), since 14.0.0-beta.0)
* 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)
* 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)
* Results notifications does not report changes to inner collections ([#7335](https://github.com/realm/realm-core/issues/7335), since 14.0.0-beta.0)

### Breaking changes
* If you want to query using @type operation, you must use 'objectlink' to match links to objects. 'object' is reserved for dictionary types.
Expand Down
11 changes: 11 additions & 0 deletions src/realm/object-store/impl/results_notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,17 @@ void ListResultsNotifier::run()
std::iota(m_run_indices->begin(), m_run_indices->end(), 0);
}

if (m_change.paths.size()) {
if (auto coll = dynamic_cast<CollectionParent*>(m_list.get())) {
for (auto& p : m_change.paths) {
// Report changes in substructure as modifications on this list
auto ndx = coll->find_index(p[0]);
if (ndx != realm::not_found)
m_change.modifications.add(ndx); // OK to insert same index again
}
}
}

calculate_changes();
}

Expand Down
8 changes: 8 additions & 0 deletions test/object-store/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,11 +1356,19 @@ TEST_CASE("nested List") {
}

SECTION("inserting in sub structure sends a change notifications") {
// Check that notifications on Results are correct
Results res = lst0.as_results();
CollectionChangeSet change1;
auto token_res = res.add_notification_callback([&](CollectionChangeSet c) {
change1 = c;
});

auto token = require_change();
write([&] {
lst0.get_dictionary(0).get_list("list").add(Mixed(42));
});
REQUIRE_INDICES(change.modifications, 0);
REQUIRE_INDICES(change1.modifications, 0);
REQUIRE(!change.collection_was_cleared);
}

Expand Down

0 comments on commit c273976

Please sign in to comment.