Skip to content

Commit

Permalink
Simplify implementation for persisting relation info in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 12, 2024
1 parent 5ff96af commit 5a9c854
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions python/templates/macros/implementations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,14 @@ void to_json(nlohmann::json& j, const {{ prefix }}{{ class.bare_type }}& value)
};

{% for relation in single_relations %}
j["{{ relation.name }}"] = nlohmann::json{
{"collectionID", value.{{ relation.getter_name(get_syntax) }}().getObjectID().collectionID },
{"index", value.{{ relation.getter_name(get_syntax) }}().getObjectID().index }};
j["{{ relation.name }}"] = nlohmann::json{value.{{ relation.getter_name(get_syntax) }}().id()};

{% endfor %}

{% for relation in multi_relations %}
j["{{ relation.name }}"] = nlohmann::json::array();
for (const auto& v : value.{{ relation.getter_name(get_syntax) }}()) {
j["{{ relation.name }}"].emplace_back(nlohmann::json{
{"collectionID", v.getObjectID().collectionID },
{"index", v.getObjectID().index }});
j["{{ relation.name }}"].emplace_back(v.id());
}

{% endfor %}
Expand Down

0 comments on commit 5a9c854

Please sign in to comment.