mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/sql/decode: fix decoding of NullTime in optional and nillable time fields (#60)
Summary:
While trying out this project I think I found a bug in the generated code when using an optional and nillable time field.
```
vet: ent/user.go:46:16: cannot use &vu.DeletedAt (value of type *sql.NullTime) as *time.Time value in assignment
```
7438104b5d made a change to the `{{ $scan }}` struct, which now always uses `{{ $f.NullType }}` as type, so the `$f.IsTime` check can now be removed. This pull request does that.
This is my fist contribution here. I hope I didn't miss anything.
Pull Request resolved: https://github.com/facebookincubator/ent/pull/60
Differential Revision: D17760925
Pulled By: a8m
fbshipit-source-id: 675005be62487b1b9eb77302b8185bd3b6ef0195
This commit is contained in:
committed by
Facebook Github Bot
parent
16fc85b785
commit
6a1c9e73fe
@@ -34,14 +34,10 @@ func ({{ $receiver }} *{{ $.Name }}) FromRows(rows *sql.Rows) error {
|
||||
}
|
||||
}
|
||||
{{- else if $f.Nillable }}
|
||||
{{- if $f.IsTime }}
|
||||
{{ $receiver }}.{{ pascal $f.Name }} = &{{ $scan }}.{{ pascal $f.Name }}
|
||||
{{- else }}
|
||||
if {{ $scan }}.{{- pascal $f.Name }}.Valid {
|
||||
{{ $receiver }}.{{ pascal $f.Name }} = new({{ $f.Type }})
|
||||
*{{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }}
|
||||
}
|
||||
{{- end }}
|
||||
if {{ $scan }}.{{- pascal $f.Name }}.Valid {
|
||||
{{ $receiver }}.{{ pascal $f.Name }} = new({{ $f.Type }})
|
||||
*{{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }}
|
||||
}
|
||||
{{- else }}
|
||||
{{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }}
|
||||
{{- end }}
|
||||
@@ -66,4 +62,4 @@ func ({{ $receiver }} *{{ $slice }}) FromRows(rows *sql.Rows) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user