From d30b9c103fd1b36e1615f7763c7418dea8771f94 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sun, 27 Sep 2026 16:07:09 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20import=20"time"=20in=20a=20g?= =?UTF-8?q?enerated=20model=20only=20for=20fields=20it=20declares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- template/v4/model.go.template | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/template/v4/model.go.template b/template/v4/model.go.template index ad8f4360..589a0b9e 100644 --- a/template/v4/model.go.template +++ b/template/v4/model.go.template @@ -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" -}}