Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-embedded links in asymmetric objects #6981

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# NEXT RELEASE

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Allow non-embedded links in asymmetric objects. ([PR #6981](https://github.com/realm/realm-core/pull/6981))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
7 changes: 0 additions & 7 deletions src/realm/object-store/object_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,6 @@ static void validate_property(Schema const& schema, ObjectSchema const& parent_o
object_name, prop.name, prop.object_type);
return;
}
if (parent_object_schema.table_type == ObjectSchema::ObjectType::TopLevelAsymmetric &&
it->table_type != ObjectSchema::ObjectType::Embedded) {
exceptions.emplace_back(
"Asymmetric table with property '%1.%2' of type '%3' cannot have a non-embedded object type.",
object_name, prop.name, string_for_property_type(prop.type));
return;
}
if (it->table_type == ObjectSchema::ObjectType::TopLevelAsymmetric) {
exceptions.emplace_back("Property '%1.%2' of type '%3' cannot be a link to an asymmetric object.",
object_name, prop.name, string_for_property_type(prop.type));
Expand Down
4 changes: 0 additions & 4 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,6 @@ ColKey Table::add_column(Table& target, StringData name)
Group* target_group = target.get_parent_group();
REALM_ASSERT_RELEASE(origin_group && target_group);
REALM_ASSERT_RELEASE(origin_group == target_group);
// Only links to embedded objects are allowed.
if (is_asymmetric() && !target.is_embedded()) {
throw IllegalOperation("Object property not supported in asymmetric table");
}
// Incoming links from an asymmetric table are not allowed.
if (target.is_asymmetric()) {
throw IllegalOperation("Ephemeral objects not supported");
Expand Down
12 changes: 6 additions & 6 deletions test/object-store/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,16 @@ TEST_CASE("Schema") {
"Property 'object.link' of type 'object' cannot be a link to an asymmetric object."));
}

SECTION("rejects link properties with asymmetric origin object") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than removing the test entirely the test should be changed to verify that it's allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIxed

SECTION("allow link properties with asymmetric origin object") {
Schema schema = {
{"object",
ObjectSchema::ObjectType::TopLevelAsymmetric,
{{"link", PropertyType::Object | PropertyType::Nullable, "link target"}}},
{"link target", {{"value", PropertyType::Int}}},
{{"_id", PropertyType::Int, Property::IsPrimary{true}},
{"link", PropertyType::Object | PropertyType::Nullable, "link target"}}},
{"link target",
{{"_id", PropertyType::Int, Property::IsPrimary{true}}, {"value", PropertyType::Int}}},
};
REQUIRE_EXCEPTION(schema.validate(SchemaValidationMode::SyncFLX), SchemaValidationFailed,
ContainsSubstring("Asymmetric table with property 'object.link' of type 'object' "
"cannot have a non-embedded object type."));
REQUIRE_NOTHROW(schema.validate(SchemaValidationMode::SyncFLX));
}

SECTION("allow embedded objects with asymmetric sync") {
Expand Down
4 changes: 2 additions & 2 deletions test/test_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5898,8 +5898,8 @@ TEST(Table_AsymmetricObjects)
tr = sg->start_write();
auto table2 = tr->add_table("target table");
table = tr->get_table("mytable");
// Outgoing link from asymmetric object is not allowed.
CHECK_THROW(table->add_column(*table2, "link"), LogicError);
// Outgoing link from asymmetric object is allowed.
CHECK_NOTHROW(table->add_column(*table2, "link"));
// Incoming link to asymmetric object is not allowed.
CHECK_THROW(table2->add_column(*table, "link"), LogicError);
tr->commit();
Expand Down