From d1fa631dbe8eb77f264a5ed8f0470d5c4b5e6425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 15 Sep 2023 19:50:54 +0200 Subject: [PATCH 1/4] Allow non-embedded links in asymmetric objects --- src/realm/object-store/object_schema.cpp | 7 ------- src/realm/table.cpp | 4 ---- 2 files changed, 11 deletions(-) diff --git a/src/realm/object-store/object_schema.cpp b/src/realm/object-store/object_schema.cpp index 5e9e9e8ccb9..7151a976805 100644 --- a/src/realm/object-store/object_schema.cpp +++ b/src/realm/object-store/object_schema.cpp @@ -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)); diff --git a/src/realm/table.cpp b/src/realm/table.cpp index 2db20c1a1f6..3fdbb1b4a10 100644 --- a/src/realm/table.cpp +++ b/src/realm/table.cpp @@ -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"); From 04cd65f274facd4ef197d0e524d08f4e8a67860e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 15 Sep 2023 19:29:02 +0200 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ffb2b01a15..b8edd5473d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,7 @@ # NEXT RELEASE ### Enhancements -* (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 * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) From a3828f41dd7f5dbdfba19d99069cf9d5768a7cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 15 Sep 2023 19:54:26 +0200 Subject: [PATCH 3/4] Add test of non-embedded links in asymmetric objects --- test/object-store/schema.cpp | 13 +++++++------ test/test_table.cpp | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/object-store/schema.cpp b/test/object-store/schema.cpp index a59039b4e11..729d5cadb92 100644 --- a/test/object-store/schema.cpp +++ b/test/object-store/schema.cpp @@ -410,16 +410,17 @@ 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") { + 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") { diff --git a/test/test_table.cpp b/test/test_table.cpp index 37eb26d95c8..aea5a30fc00 100644 --- a/test/test_table.cpp +++ b/test/test_table.cpp @@ -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(); From 49cd88e3e489769559a17edfee7c554e274ea291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 15 Sep 2023 20:36:07 +0200 Subject: [PATCH 4/4] Fix lint --- test/object-store/schema.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/object-store/schema.cpp b/test/object-store/schema.cpp index 729d5cadb92..b86fba23cd7 100644 --- a/test/object-store/schema.cpp +++ b/test/object-store/schema.cpp @@ -416,9 +416,8 @@ TEST_CASE("Schema") { ObjectSchema::ObjectType::TopLevelAsymmetric, {{"_id", PropertyType::Int, Property::IsPrimary{true}}, {"link", PropertyType::Object | PropertyType::Nullable, "link target"}}}, - {"link target", - {{"_id", PropertyType::Int, Property::IsPrimary{true}}, - {"value", PropertyType::Int}}}, + {"link target", + {{"_id", PropertyType::Int, Property::IsPrimary{true}}, {"value", PropertyType::Int}}}, }; REQUIRE_NOTHROW(schema.validate(SchemaValidationMode::SyncFLX)); }