Skip to content

Commit

Permalink
Add support for keypaths crossing backlins
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Melchior committed Nov 15, 2023
1 parent 046616f commit 9cfa503
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/realm/object-store/c_api/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::optional<KeyPathArray> build_key_path_array(realm_key_path_array_t* key_pat
return ret;
}

static KeyPathArray create_key_path_array(const ObjectSchema& object_schema, const Schema& schema,
static KeyPathArray create_key_path_array(const Group& group, const ObjectSchema& object_schema, const Schema& schema,
const char** all_key_paths_begin, const char** all_key_paths_end)
{
KeyPathArray resolved_key_path_array;
Expand All @@ -99,7 +99,20 @@ static KeyPathArray create_key_path_array(const ObjectSchema& object_schema, con
}
prop = schema_at_index->property_for_public_name(property);
if (prop) {
resolved_key_path.emplace_back(schema_at_index->table_key, prop->column_key);
if ((to_underlying(prop->type & PropertyType::LinkingObjects)) != 0) {
// TODO Why isn't this just filled in the PropertyInfo::column_key?
auto originClass = schema.find(prop->object_type);
if (originClass != schema.end()) {
ColKey forwardColKey = originClass->property_for_name(prop->link_origin_property_name)->column_key;
ConstTableRef originTable = group.get_table(originClass->table_key);
resolved_key_path.emplace_back(schema_at_index->table_key, originTable->get_opposite_column(forwardColKey));
} else {
throw InvalidArgument(util::format("Property '%1' in Keypath '%2' is a backlink that points to a class that could not be found: %3",
property, *it, prop->object_type));
}
} else {
resolved_key_path.emplace_back(schema_at_index->table_key, prop->column_key);
}
schema_at_index = nullptr;
}
else {
Expand All @@ -121,9 +134,10 @@ RLM_API realm_key_path_array_t* realm_create_key_path_array(const realm_t* realm
return wrap_err([&]() {
KeyPathArray ret;
if (user_key_paths) {
const Group& group = (*realm)->read_group();
const Schema& schema = (*realm)->schema();
const ObjectSchema& object_schema = schema_for_table(*realm, TableKey(object_class_key));
ret = create_key_path_array(object_schema, schema, user_key_paths, user_key_paths + user_key_paths_count);
ret = create_key_path_array(group, object_schema, schema, user_key_paths, user_key_paths + user_key_paths_count);
}
return new realm_key_path_array_t(std::move(ret));
});
Expand Down

0 comments on commit 9cfa503

Please sign in to comment.