diff --git a/drogon_ctl/templates/model_h.csp b/drogon_ctl/templates/model_h.csp index 9dc531be..16ef8a72 100644 --- a/drogon_ctl/templates/model_h.csp +++ b/drogon_ctl/templates/model_h.csp @@ -42,27 +42,32 @@ namespace [[dbName]] { <%c++ auto &schema=@@.get("schema"); -if(!schema.empty()) -{ - $$<<"namespace "<>("relationships"); + if(!schema.empty()) + { + $$<<"namespace "< relationshipClassNames; + auto &relationships=@@.get>("relationships"); for(auto &relationship : relationships) { - auto &name=relationship.targetTableName(); - auto relationshipClassName=nameTransform(name, true); + auto &name = relationship.targetTableName(); + auto relationshipClassName = nameTransform(name, true); + relationshipClassNames.push_back(relationshipClassName); + if(relationship.type() == Relationship::Type::ManyToMany) + { + auto &pivotTableName = relationship.pivotTable().tableName(); + auto pivotTableClassName = nameTransform(pivotTableName, true); + relationshipClassNames.push_back(pivotTableClassName); + } + } + std::sort(relationshipClassNames.begin(), relationshipClassNames.end()); + relationshipClassNames.erase(std::unique(relationshipClassNames.begin(), relationshipClassNames.end()), relationshipClassNames.end()); + for(std::string &relationshipClassName : relationshipClassNames) + { %> class {%relationshipClassName%}; <%c++ - if(relationship.type() == Relationship::Type::ManyToMany) - { - auto &pivotTableName=relationship.pivotTable().tableName(); - auto pivotTableClassName=nameTransform(pivotTableName, true); -%> -class {%pivotTableClassName%}; -<%c++ - } } %>