Remove repeated class names on relationships from model generator. (#792)

This commit is contained in:
0rangeFox 2021-04-09 15:15:49 +01:00 committed by GitHub
parent 4b8d08f20f
commit c65051a8f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 16 deletions

View File

@ -42,27 +42,32 @@ namespace [[dbName]]
{
<%c++
auto &schema=@@.get<std::string>("schema");
if(!schema.empty())
{
$$<<"namespace "<<schema<<"\n";
$$<<"{\n";
}
auto &relationships=@@.get<std::vector<Relationship>>("relationships");
if(!schema.empty())
{
$$<<"namespace "<<schema<<"\n";
$$<<"{\n";
}
std::vector<std::string> relationshipClassNames;
auto &relationships=@@.get<std::vector<Relationship>>("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++
}
}
%>