fix: improve FK handling in generated model class code
also tweak default revision message for new table
This commit is contained in:
parent
2b5775b348
commit
34704acf24
2 changed files with 12 additions and 16 deletions
|
|
@ -15,16 +15,6 @@ class ${model_name}(model.Base):
|
||||||
${description}
|
${description}
|
||||||
"""
|
"""
|
||||||
__tablename__ = "${table_name}"
|
__tablename__ = "${table_name}"
|
||||||
% if any([c["data_type"]["type"] == "_fk_uuid_" for c in columns]):
|
|
||||||
__table_args__ = (
|
|
||||||
% for column in columns:
|
|
||||||
% if column["data_type"]["type"] == "_fk_uuid_":
|
|
||||||
sa.ForeignKeyConstraint(["${column['name']}"], ["${column['data_type']['reference']}.uuid"],
|
|
||||||
name="${table_name}_fk_${column['data_type']['reference']}"),
|
|
||||||
% endif
|
|
||||||
% endfor
|
|
||||||
)
|
|
||||||
% endif
|
|
||||||
% if versioned:
|
% if versioned:
|
||||||
% if all([c["versioned"] for c in columns]):
|
% if all([c["versioned"] for c in columns]):
|
||||||
__versioned__ = {}
|
__versioned__ = {}
|
||||||
|
|
@ -48,17 +38,23 @@ class ${model_name}(model.Base):
|
||||||
|
|
||||||
% if column["name"] == "uuid":
|
% if column["name"] == "uuid":
|
||||||
uuid = model.uuid_column()
|
uuid = model.uuid_column()
|
||||||
% else:
|
% elif column["data_type"]["type"] == "_fk_uuid_":
|
||||||
${column["name"]} = sa.Column(${column["formatted_data_type"]}, nullable=${column["nullable"]}, doc="""
|
${column["name"]} = model.uuid_fk_column("${column['data_type']['reference']}.uuid",
|
||||||
${column["description"] or ""}
|
nullable=${column["nullable"]})
|
||||||
""")
|
% if column["relationship"]:
|
||||||
% if column["data_type"]["type"] == "_fk_uuid_" and column["relationship"]:
|
|
||||||
${column["relationship"]["name"]} = orm.relationship(
|
${column["relationship"]["name"]} = orm.relationship(
|
||||||
"${column['relationship']['reference_model']}",
|
"${column['relationship']['reference_model']}",
|
||||||
doc="""
|
doc="""
|
||||||
${column["description"] or ""}
|
${column["description"] or ""}
|
||||||
""")
|
""")
|
||||||
% endif
|
% endif
|
||||||
|
% else:
|
||||||
|
${column["name"]} = sa.Column(
|
||||||
|
${column["formatted_data_type"]},
|
||||||
|
nullable=${column["nullable"]},
|
||||||
|
doc="""
|
||||||
|
${column["description"] or ""}
|
||||||
|
""")
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -947,7 +947,7 @@
|
||||||
} else {
|
} else {
|
||||||
this.modelImportProblem = false
|
this.modelImportProblem = false
|
||||||
this.modelImported = this.modelImportName
|
this.modelImported = this.modelImportName
|
||||||
this.revisionMessage = `add table for ${"$"}{this.tableModelTitlePlural}`
|
this.revisionMessage = `add ${"$"}{this.tableModelTitlePlural}`
|
||||||
}
|
}
|
||||||
}, 200)
|
}, 200)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue