From 341c337b0015c5db077e6262273c24dc6c2b8bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Thu, 23 May 2024 11:05:28 +0200 Subject: [PATCH] Include "$set" in set of links --- src/realm/list.cpp | 16 ++------- src/realm/set.cpp | 14 ++------ test/expected_xjson_linkset1.json | 29 +++++++++++++++- test/expected_xjson_plus_linkset1.json | 48 +++++++++++++++----------- 4 files changed, 60 insertions(+), 47 deletions(-) diff --git a/src/realm/list.cpp b/src/realm/list.cpp index 1f47ec702bc..d3f94bd895a 100644 --- a/src/realm/list.cpp +++ b/src/realm/list.cpp @@ -136,7 +136,7 @@ void CollectionBaseImpl::to_json(std::ostream& out, JSONOutputMode outp if (i > 0) out << ","; Mixed val = get_any(i); - if (val.is_type(type_TypedLink)) { + if (val.is_type(type_Link, type_TypedLink)) { fn(val); } else { @@ -951,19 +951,9 @@ void LnkLst::remove_all_target_rows() } } -void LnkLst::to_json(std::ostream& out, JSONOutputMode, util::FunctionRef fn) const +void LnkLst::to_json(std::ostream& out, JSONOutputMode mode, util::FunctionRef fn) const { - out << "["; - - auto sz = m_list.size(); - for (size_t i = 0; i < sz; i++) { - if (i > 0) - out << ","; - Mixed val(m_list.get(i)); - fn(val); - } - - out << "]"; + m_list.to_json(out, mode, fn); } void LnkLst::replace_link(ObjKey old_val, ObjKey new_val) diff --git a/src/realm/set.cpp b/src/realm/set.cpp index 74d4e51c0f6..24c8f1a4e24 100644 --- a/src/realm/set.cpp +++ b/src/realm/set.cpp @@ -483,19 +483,9 @@ void LnkSet::remove_all_target_rows() } } -void LnkSet::to_json(std::ostream& out, JSONOutputMode, util::FunctionRef fn) const +void LnkSet::to_json(std::ostream& out, JSONOutputMode mode, util::FunctionRef fn) const { - out << "["; - - auto sz = m_set.size(); - for (size_t i = 0; i < sz; i++) { - if (i > 0) - out << ","; - Mixed val(m_set.get(i)); - fn(val); - } - - out << "]"; + m_set.to_json(out, mode, fn); } void set_sorted_indices(size_t sz, std::vector& indices, bool ascending) diff --git a/test/expected_xjson_linkset1.json b/test/expected_xjson_linkset1.json index 6f04a31f6a2..a07254e7001 100644 --- a/test/expected_xjson_linkset1.json +++ b/test/expected_xjson_linkset1.json @@ -1 +1,28 @@ -[{"primaryKey":"t1o1","int1":{"$numberLong": "100"},"linkA":["t2o2"]},{"primaryKey":"t1o3","int1":{"$numberLong": "300"},"linkA":[]},{"primaryKey":"t1o2","int1":{"$numberLong": "200"},"linkA":["t2o2","t2o3"]}] \ No newline at end of file +[ + { + "primaryKey": "t1o1", + "int1": { + "$numberLong": "100" + }, + "linkA": [ + "t2o2" + ] + }, + { + "primaryKey": "t1o3", + "int1": { + "$numberLong": "300" + }, + "linkA": [] + }, + { + "primaryKey": "t1o2", + "int1": { + "$numberLong": "200" + }, + "linkA": [ + "t2o2", + "t2o3" + ] + } +] diff --git a/test/expected_xjson_plus_linkset1.json b/test/expected_xjson_plus_linkset1.json index d2a376f0512..23038c2ec9b 100644 --- a/test/expected_xjson_plus_linkset1.json +++ b/test/expected_xjson_plus_linkset1.json @@ -4,40 +4,46 @@ "int1": { "$numberLong": "100" }, - "linkA": [ - { - "$link": { - "table": "table2", - "key": "t2o2" + "linkA": { + "$set": [ + { + "$link": { + "table": "table2", + "key": "t2o2" + } } - } - ] + ] + } }, { "primaryKey": "t1o3", "int1": { "$numberLong": "300" }, - "linkA": [] + "linkA": { + "$set": [] + } }, { "primaryKey": "t1o2", "int1": { "$numberLong": "200" }, - "linkA": [ - { - "$link": { - "table": "table2", - "key": "t2o2" + "linkA": { + "$set": [ + { + "$link": { + "table": "table2", + "key": "t2o2" + } + }, + { + "$link": { + "table": "table2", + "key": "t2o3" + } } - }, - { - "$link": { - "table": "table2", - "key": "t2o3" - } - } - ] + ] + } } ]