Skip to content

Commit 22fd7a3

Browse files
author
Kasper Overgård Nielsen
authored
Allow non-embedded links in asymmetric objects (#6981)
* Allow non-embedded links in asymmetric objects * Update CHANGELOG * Add test of non-embedded links in asymmetric objects * Fix lint
1 parent 4b413aa commit 22fd7a3

File tree

5 files changed

+9
-21
lines changed

5 files changed

+9
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# NEXT RELEASE
22

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

76
### Fixed
87
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)

src/realm/object-store/object_schema.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,6 @@ static void validate_property(Schema const& schema, ObjectSchema const& parent_o
296296
object_name, prop.name, prop.object_type);
297297
return;
298298
}
299-
if (parent_object_schema.table_type == ObjectSchema::ObjectType::TopLevelAsymmetric &&
300-
it->table_type != ObjectSchema::ObjectType::Embedded) {
301-
exceptions.emplace_back(
302-
"Asymmetric table with property '%1.%2' of type '%3' cannot have a non-embedded object type.",
303-
object_name, prop.name, string_for_property_type(prop.type));
304-
return;
305-
}
306299
if (it->table_type == ObjectSchema::ObjectType::TopLevelAsymmetric) {
307300
exceptions.emplace_back("Property '%1.%2' of type '%3' cannot be a link to an asymmetric object.",
308301
object_name, prop.name, string_for_property_type(prop.type));

src/realm/table.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,6 @@ ColKey Table::add_column(Table& target, StringData name)
415415
Group* target_group = target.get_parent_group();
416416
REALM_ASSERT_RELEASE(origin_group && target_group);
417417
REALM_ASSERT_RELEASE(origin_group == target_group);
418-
// Only links to embedded objects are allowed.
419-
if (is_asymmetric() && !target.is_embedded()) {
420-
throw IllegalOperation("Object property not supported in asymmetric table");
421-
}
422418
// Incoming links from an asymmetric table are not allowed.
423419
if (target.is_asymmetric()) {
424420
throw IllegalOperation("Ephemeral objects not supported");

test/object-store/schema.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,16 @@ TEST_CASE("Schema") {
410410
"Property 'object.link' of type 'object' cannot be a link to an asymmetric object."));
411411
}
412412

413-
SECTION("rejects link properties with asymmetric origin object") {
413+
SECTION("allow link properties with asymmetric origin object") {
414414
Schema schema = {
415415
{"object",
416416
ObjectSchema::ObjectType::TopLevelAsymmetric,
417-
{{"link", PropertyType::Object | PropertyType::Nullable, "link target"}}},
418-
{"link target", {{"value", PropertyType::Int}}},
417+
{{"_id", PropertyType::Int, Property::IsPrimary{true}},
418+
{"link", PropertyType::Object | PropertyType::Nullable, "link target"}}},
419+
{"link target",
420+
{{"_id", PropertyType::Int, Property::IsPrimary{true}}, {"value", PropertyType::Int}}},
419421
};
420-
REQUIRE_EXCEPTION(schema.validate(SchemaValidationMode::SyncFLX), SchemaValidationFailed,
421-
ContainsSubstring("Asymmetric table with property 'object.link' of type 'object' "
422-
"cannot have a non-embedded object type."));
422+
REQUIRE_NOTHROW(schema.validate(SchemaValidationMode::SyncFLX));
423423
}
424424

425425
SECTION("allow embedded objects with asymmetric sync") {

test/test_table.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5898,8 +5898,8 @@ TEST(Table_AsymmetricObjects)
58985898
tr = sg->start_write();
58995899
auto table2 = tr->add_table("target table");
59005900
table = tr->get_table("mytable");
5901-
// Outgoing link from asymmetric object is not allowed.
5902-
CHECK_THROW(table->add_column(*table2, "link"), LogicError);
5901+
// Outgoing link from asymmetric object is allowed.
5902+
CHECK_NOTHROW(table->add_column(*table2, "link"));
59035903
// Incoming link to asymmetric object is not allowed.
59045904
CHECK_THROW(table2->add_column(*table, "link"), LogicError);
59055905
tr->commit();

0 commit comments

Comments
 (0)