fix🐛: import "time" in a generated model only for fields it declares

The model template imported "time" for any queryable time.Time column,
though whether a column is queryable only shapes the DTO. A queryable
created_at, which the model takes from models.ModelTime rather than
declaring, left the import unused and the generated package failed to
compile.
This commit is contained in:
zhangwenjian
2026-09-27 16:07:09 +08:00
parent 77fddfa356
commit d30b9c103f
+6 -6
View File
@@ -1,14 +1,14 @@
package models
import (
{{- /*
The model declares a time.Time field for every such column except the
three models.ModelTime supplies. Whether a column is queryable is the
DTO's business, not the model's: counting it here imported "time" for a
queryable created_at that the model never declares.
*/ -}}
{{- $bb := false -}}
{{- range .Columns -}}
{{- $z := .IsQuery -}}
{{- if ($z) -}}
{{- if eq .GoType "time.Time" -}}{{- $bb = true -}}{{- end -}}
{{- end -}}
{{- end -}}
{{- range .Columns -}}
{{- if eq .GoField "CreatedAt" -}}
{{- else if eq .GoField "UpdatedAt" -}}
{{- else if eq .GoField "DeletedAt" -}}