Skip to content

Commit

Permalink
Make Results::get return proper nested collections
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Apr 15, 2024
1 parent 975970b commit d37888b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/realm/object-store/results.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,21 @@ auto Results::dispatch(Fn&& fn) const
}

template <typename Context>
auto Results::get(Context& ctx, size_t row_ndx)
auto Results::get(Context& ctx, size_t ndx)
{
return dispatch([&](auto t) {
return ctx.box(this->get<std::decay_t<decltype(*t)>>(row_ndx));
using U = std::decay_t<decltype(*t)>;
auto value = this->get<U>(ndx);
if constexpr (std::is_same_v<U, Mixed>) {
if (value.is_type(type_Dictionary)) {
return ctx.box(get_dictionary(ndx));
}
if (value.is_type(type_List)) {
return ctx.box(get_list(ndx));
}
}

return ctx.box(value);
});
}

Expand Down
4 changes: 4 additions & 0 deletions test/object-store/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") {
REQUIRE(val.is_type(type_List));
auto list = results.get_list(1);
REQUIRE(list.is_valid());

CppContext ctx(r);
CHECK(util::any_cast<object_store::Dictionary&&>(results.get(ctx, 0)).is_valid());
CHECK(util::any_cast<List&&>(results.get(ctx, 1)).is_valid());
}
}

Expand Down

0 comments on commit d37888b

Please sign in to comment.