Skip to content

Commit

Permalink
Include "$set" in set of links
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed May 28, 2024
1 parent ea8a55d commit 341c337
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 47 deletions.
16 changes: 3 additions & 13 deletions src/realm/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void CollectionBaseImpl<LstBase>::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 {
Expand Down Expand Up @@ -951,19 +951,9 @@ void LnkLst::remove_all_target_rows()
}
}

void LnkLst::to_json(std::ostream& out, JSONOutputMode, util::FunctionRef<void(const Mixed&)> fn) const
void LnkLst::to_json(std::ostream& out, JSONOutputMode mode, util::FunctionRef<void(const Mixed&)> 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)
Expand Down
14 changes: 2 additions & 12 deletions src/realm/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,9 @@ void LnkSet::remove_all_target_rows()
}
}

void LnkSet::to_json(std::ostream& out, JSONOutputMode, util::FunctionRef<void(const Mixed&)> fn) const
void LnkSet::to_json(std::ostream& out, JSONOutputMode mode, util::FunctionRef<void(const Mixed&)> 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<size_t>& indices, bool ascending)
Expand Down
29 changes: 28 additions & 1 deletion test/expected_xjson_linkset1.json
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
[{"primaryKey":"t1o1","int1":{"$numberLong": "100"},"linkA":["t2o2"]},{"primaryKey":"t1o3","int1":{"$numberLong": "300"},"linkA":[]},{"primaryKey":"t1o2","int1":{"$numberLong": "200"},"linkA":["t2o2","t2o3"]}]
[
{
"primaryKey": "t1o1",
"int1": {
"$numberLong": "100"
},
"linkA": [
"t2o2"
]
},
{
"primaryKey": "t1o3",
"int1": {
"$numberLong": "300"
},
"linkA": []
},
{
"primaryKey": "t1o2",
"int1": {
"$numberLong": "200"
},
"linkA": [
"t2o2",
"t2o3"
]
}
]
48 changes: 27 additions & 21 deletions test/expected_xjson_plus_linkset1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
]
}
}
]

0 comments on commit 341c337

Please sign in to comment.